[Mapbender-commits] r6120 - branches/3_dev/core/lib
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Sun May 9 12:02:50 EDT 2010
Author: astrid_emde
Date: 2010-05-09 12:02:50 -0400 (Sun, 09 May 2010)
New Revision: 6120
Added:
branches/3_dev/core/lib/class_Connector.php
branches/3_dev/core/lib/class_Wms.php
branches/3_dev/core/lib/class_bbox.php
branches/3_dev/core/lib/class_georss.php
branches/3_dev/core/lib/class_georss_factory.php
branches/3_dev/core/lib/class_georss_geometry.php
branches/3_dev/core/lib/class_georss_item.php
branches/3_dev/core/lib/class_gml2.php
branches/3_dev/core/lib/class_point.php
branches/3_dev/core/lib/class_rss.php
branches/3_dev/core/lib/class_rss_factory.php
branches/3_dev/core/lib/class_rss_item.php
branches/3_dev/core/lib/initWms.php
branches/3_dev/core/lib/mod_map_messages.php
Modified:
branches/3_dev/core/lib/class_Mapbender.php
Log:
for template-basic from trunk,merges classes from trunk, class names not modified yet
Added: branches/3_dev/core/lib/class_Connector.php
===================================================================
--- branches/3_dev/core/lib/class_Connector.php (rev 0)
+++ branches/3_dev/core/lib/class_Connector.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,326 @@
+<?php
+# $Id: class_connector.php 5707 2010-03-02 13:10:41Z armin11 $
+# http://www.mapbender.org/index.php/class_connector
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+/**
+ * Establishes a connection to a given URL (and loads the content).
+ * Supports HTTP (GET and POST), cURL and socket connections.
+ *
+ * @class
+ */
+class connector {
+
+ var $file;
+ private $connectionType;
+ private $httpType = "get";
+ private $httpVersion = "1.0";
+ private $httpPostData;
+ private $httpContentType = "text/html";
+
+ /**
+ * @constructor
+ * @param String url the URL that will be loaded (optional)
+ */
+ public function __construct() {
+ $this->set("connectionType", CONNECTION);
+ if (func_num_args() == 1) {
+ $url = func_get_arg(0);
+ if ($url) {
+ $this->load($url);
+ }
+ }
+ else if (func_num_args() == 2) {
+ $auth = func_get_arg(1);
+ $url = func_get_arg(0);
+ if ($url) {
+ $this->load($url,$auth);
+ }
+ }
+ }
+
+ /**
+ * Loads content from the given URL.
+ */
+ public function load($url) {
+ if (!$url) {
+ $e = new mb_exception("connector: no URL given");
+ return false;
+ }
+ switch ($this->connectionType) {
+ case "curl":
+ if (func_num_args() == 2) {
+ $auth = func_get_arg(1);
+ if (isset($auth)) {
+ $this->file = $this->getCURL($url,$auth);
+ }
+ }
+ else {
+ $this->file = $this->getCURL($url);
+ }
+ break;
+ case "http":
+ $this->file = $this->getHTTP($url);
+ break;
+ case "socket":
+ $this->file = $this->getSOCKET($url);
+ break;
+ }
+ if(!$this->file){
+ $e = new mb_exception("connector: unable to load: ".$url);
+ return false;
+ }
+ return $this->file;
+ }
+
+ /**
+ * Sets the environment variables. The following can be set:
+ * - connectionType ("http", "curl", "socket")
+ * - httpType ("get", "post")
+ * - etc.
+ */
+ public function set ($key, $value) {
+ switch ($key) {
+ case "connectionType":
+ if ($this->isValidConnectionType($value)) {
+ $this->connectionType = $value;
+ }
+ break;
+
+ case "httpVersion":
+ if (in_array($value, array("1.0", "1.1"))) {
+ $this->httpVersion = $value;
+ }
+ else {
+ $e = new mb_exception("class_connector.php: invalid http type '" . $value . "'");
+ }
+ break;
+
+ case "httpType":
+ if (in_array(mb_strtoupper($value), array("POST", "GET"))) {
+ $this->httpType = $value;
+ }
+ else {
+ $e = new mb_exception("class_connector.php: invalid http type '" . $value . "'");
+ }
+ break;
+
+ case "httpPostData":
+ $this->httpPostData = $value;
+ break;
+
+ case "httpContentType":
+ if ($this->isValidHttpContentType($value)) {
+ $this->httpContentType = $value;
+ }
+ break;
+ }
+ }
+
+ private function isValidConnectionType ($value) {
+ if (in_array(mb_strtoupper($value), array("HTTP", "CURL", "SOCKET"))) {
+ return true;
+ }
+ else {
+ $e = new mb_exception("class_connector.php: invalid connection type '" . $value . "'");
+ return false;
+ }
+ }
+
+ private function isValidHttpContentType ($value) {
+ $validHttpContentTypeArray = array("XML","TEXT/XML");
+ if (in_array(mb_strtoupper($value), $validHttpContentTypeArray)) {
+ switch (mb_strtoupper($value)) {
+ case "XML":
+ $this->httpContentType = "application/xml";
+ break;
+ }
+ return true;
+ }
+ else {
+ $e = new mb_exception("class_connector.php: invalid HTTP content type '" . $value . "'");
+ return false;
+ }
+ }
+
+ private function getCURL($url){
+ $url=Str_replace(" ","+",$url); //to have no problems with image/png; mode=24bit!
+ $url=str_replace(";","%3B",$url);
+ if (func_num_args() == 2) {
+ $auth = func_get_arg(1);
+ } //auth should be an array of ['username', 'realm', 'password', 'auth_type'] - or false - problem would be, that these are stored without hashing them!
+ $ch = curl_init ($url);
+// curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+ //allow https connections and handle certificates quite simply ;-)
+ curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+ //get hostname/ip out of url
+ //$host = parse_url($url,PHP_URL_HOST);
+ $arURL = parse_url($url);
+ $host = $arURL["host"];
+ $port = $arURL["port"];
+ if($port == ''){
+ $port = 80;
+ }
+ $path = $arURL["path"];
+
+ // fill array (HOSTs not for Proxy)
+ $NOT_PROXY_HOSTS_array = explode(",", NOT_PROXY_HOSTS);
+ if(CONNECTION_PROXY != "" AND (in_array($host, $NOT_PROXY_HOSTS_array)!= true)){
+ curl_setopt($ch, CURLOPT_PROXY,CONNECTION_PROXY.":".CONNECTION_PORT);
+ }
+ if(CONNECTION_PASSWORD != ""){
+ curl_setopt ($ch, CURLOPT_PROXYUSERPWD, CONNECTION_USER.':'.CONNECTION_PASSWORD);
+ }
+ //TODO maybe allow basic authentication for client, but this will store the passwords in plain text
+ //TODO: store the passwords as digest hash. Therefor we have to handle the realm which is defined in the 401 header and return it back to the scripts like mod_loadwms.php to store the digest into the database - problem: curl cannot handle digest connection without clear username and password - we have to send our own headers
+ if(isset($auth) && $auth != false) {
+ curl_setopt($ch, CURLOPT_USERPWD, $auth['username'].':'.$auth['password']);
+ if ($auth['auth_type'] == 'digest') {
+ curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
+ }
+ if ($auth['auth_type'] == 'basic') {
+ curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
+ }
+ }
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+
+
+ //if httpType is POST, set CURLOPT_POST and CURLOPT_POSTFIELDS
+ //and set a usefull http header
+ if(strtoupper($this->httpType) == 'POST'){
+ $headers = array(
+ "POST ".$path." HTTP/1.1",
+ "Content-type: ".$this->httpContentType."; charset=".CHARSET,
+ "Cache-Control: no-cache",
+ "Pragma: no-cache",
+ "Content-length: ".strlen($this->httpPostData)
+ );
+ $e = new mb_exception("connector: CURL POST: ".$this->httpPostData);
+ #$e = new mb_exception("connector: CURL POST HEADER: ".print_r($headers));
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->httpPostData);
+ }
+
+ $useragent=CONNECTION_USERAGENT;
+ $e = new mb_notice("connector: CURL connect to: ".$url);
+ curl_setopt ($ch,CURLOPT_USERAGENT,$useragent);
+ $file = curl_exec ($ch);
+ //handle http authentication
+ $info = curl_getinfo($ch);
+
+ if ($info['http_code'] == '401') {
+ curl_close ($ch);
+ return $info['http_code'];
+ }
+ curl_close ($ch);
+
+ return $file;
+ }
+
+ private function getHTTP($url){
+ if ($this->httpType == "get") {
+ return @file_get_contents($url);
+ }
+ else {
+ $errno = 0;
+ $errstr = "";
+ $urlComponentArray = parse_url($url);
+ $scheme = $urlComponentArray["scheme"];
+ $host = $urlComponentArray["host"];
+ $port = $urlComponentArray["port"];
+ if ($port == "") {
+ if ($scheme == "https") {
+ $port = 443;
+ }
+ else {
+ $port = 80;
+ }
+ }
+ $path = $urlComponentArray["path"];
+ $query = $urlComponentArray["query"];
+ $buf = '';
+ if ($scheme == "https") {
+ $fp = fsockopen("ssl://". $host, $port, $errno, $errstr);
+ }
+ else {
+ $fp = fsockopen($host, $port);
+ }
+ $postStr = "";
+ $postPath = "POST " . $path . "?" . $query . " HTTP/".$this->httpVersion . "\r\n";
+ $postStr .= $postPath;
+ fputs($fp, $postPath);
+
+ $postHost = "Host: " . $host . "\r\n";
+ $postStr .= $postHost;
+ fputs($fp, $postHost);
+
+ if ($this->isValidHttpContentType($this->httpContentType)) {
+ $postContentType = "Content-type: " . $this->httpContentType . "\r\n";
+ $postStr .= $postContentType;
+ fputs($fp, $postContentType);
+ }
+ $postContentLength = "Content-length: " . strlen($this->httpPostData) . "\r\n";
+ $postStr .= $postContentLength;
+ fputs($fp, $postContentLength);
+
+ $postClose = "Connection: close\r\n\r\n";
+ $postStr .= $postClose;
+ fputs($fp, $postClose);
+
+ $postStr .= $this->httpPostData;
+ fputs($fp, $this->httpPostData);
+
+ new mb_notice("connector.http.postData: ".$this->httpPostData);
+
+ $xmlstr = false;
+ while (!feof($fp)) {
+ $content = fgets($fp,4096);
+// if( strpos($content, '<?xml') === 0){
+ if( strpos($content, '<') === 0){
+ $xmlstr = true;
+ }
+ if($xmlstr == true){
+ $buf .= $content;
+ }
+ }
+ fclose($fp);
+// new mb_notice("connector.http.response: ".$buf);
+ return $buf;
+ }
+ }
+
+ private function getSOCKET($url){
+ $r = "";
+ $fp = fsockopen (CONNECTION_PROXY, CONNECTION_PORT, $errno, $errstr, 30);
+ if (!$fp) {
+ echo "$errstr ($errno)<br />\n";
+ }
+ else {
+ fputs ($fp, "GET ".$url." HTTP/1.0\r\n\r\n");
+ while (!feof($fp)) {
+ $r .= fgets($fp,4096);
+ }
+ fclose($fp);
+ return $r;
+ }
+ }
+}
+?>
Modified: branches/3_dev/core/lib/class_Mapbender.php
===================================================================
--- branches/3_dev/core/lib/class_Mapbender.php 2010-05-09 16:00:07 UTC (rev 6119)
+++ branches/3_dev/core/lib/class_Mapbender.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -53,6 +53,7 @@
"languageId" => Mapbender::session()->get("mb_lang"),
"publicUser" => PUBLIC_USER,
"login" => LOGIN,
+ "resolution" => MB_RESOLUTION,
"log" => array(
"js" => LOG_JS,
"level" => LOG_LEVEL,
Added: branches/3_dev/core/lib/class_Wms.php
===================================================================
--- branches/3_dev/core/lib/class_Wms.php (rev 0)
+++ branches/3_dev/core/lib/class_Wms.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,2641 @@
+<?php
+# $Id: class_wms.php 6058 2010-05-03 10:28:08Z christoph $
+# http://www.mapbender.org/index.php/class_wms
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_Connector.php");
+require_once(dirname(__FILE__)."/class_User.php");
+require_once(dirname(__FILE__)."/class_Administration.php");
+require_once(dirname(__FILE__)."/class_georss_factory.php");
+
+class wms {
+ var $lastURL;
+ var $wms_id;
+ var $wms_status;
+ var $wms_version;
+ var $wms_title;
+ var $wms_abstract;
+ var $wms_getcapabilities;
+ var $wms_getcapabilities_doc;
+ var $wms_getmap;
+ var $wms_getfeatureinfo;
+ var $wms_getlegendurl;
+ var $wms_upload_url;
+ var $wms_srs = array();
+
+ var $fees;
+ var $accessconstraints;
+ var $contactperson;
+ var $contactposition;
+ var $contactorganization;
+ var $address;
+ var $city;
+ var $stateorprovince;
+ var $postcode;
+ var $country;
+ var $contactvoicetelephone;
+ var $contactfacsimiletelephone;
+ var $contactelectronicmailaddress;
+
+ var $wms_keyword = array();
+ var $data_type = array();
+ var $data_format = array();
+ var $objLayer = array();
+
+ var $wms_supportsld;
+ var $wms_userlayer;
+ var $wms_userstyle;
+ var $wms_remotewfs;
+
+ var $gui_wms_mapformat;
+ var $gui_wms_featureinfoformat;
+ var $gui_wms_exceptionformat;
+ var $gui_wms_epsg;
+ var $gui_wms_sldurl;
+
+ var $default_epsg = 0;
+ var $overwrite = true;
+
+ // write a GeoRSS feed?
+ const GEORSS = true;
+ // append items to the feed when a new WMS is inserted?
+ const GEORSS_APPEND_ON_INSERT = true;
+ // append items to the feed when an existing WMS is updated?
+ const GEORSS_APPEND_ON_UPDATE = true;
+ // append items to the feed only when an existing WMS is updated
+ // and new layers have been added?
+ const GEORSS_APPEND_ON_UPDATE_NEWLAYERS = true;
+
+ function wms() {
+ }
+
+ public static function getWmsMetadataUrl ($wmsId) {
+ return preg_replace(
+ "/(.*)frames\/login.php/",
+ "$1php/mod_layerMetadata.php?id=",
+ LOGIN
+ ) . $wmsId;
+ }
+
+ public static function isOwsProxyUrl ($getmap) {
+// $e = new mb_notice("isOwsProxyUrl? " . $getmap);
+ $result = preg_match("/^.*owsproxy.([^i][\w\d]+)\/([\w\d]{32})\/?.*$/", $getmap);
+// $e = new mb_notice("result: " . $result);
+ return $result;
+ }
+
+ private function replaceSessionIdInOwsProxyUrl ($getMap) {
+// $e = new mb_notice("replaceSessionIdInOwsProxyUrl: ");
+ $e = new mb_notice("before: " . $getMap);
+ $pattern = '/(^.*owsproxy.)([^i][\w\d]+)(\/)([\w\d]{32})(\/?.*)$/';
+ $getMap1= preg_replace($pattern, "$1",$getMap);
+ $getMap2= preg_replace($pattern, "$3$4$5",$getMap);
+ $getMap = $getMap1.session_id().$getMap2;
+ $e = new mb_notice("after: " . $getMap);
+ return $getMap;
+ }
+
+ public static function getHashFromOwsProxyUrl ($getMap) {
+// $e = new mb_notice("replaceSessionIdInOwsProxyUrl: " . $getMap);
+ $result = preg_replace("/^.*owsproxy.([^i][\w\d]+)\/([\w\d]{32})\/?.*$/", "$2", $getMap);
+// $e = new mb_notice("result: " . $result);
+ return $result;
+ }
+
+ private function getWmsIdByOwsProxyHash($md5) {
+ $sql = "SELECT wms_id FROM wms WHERE wms_owsproxy = $1";
+ $v = array($md5);
+ $t = array("s");
+ $res = db_prep_query($sql, $v, $t);
+ $row = db_fetch_row($res);
+ if ($row["wms_id"]) {
+ return $row["wms_id"];
+ }
+ return null;
+ }
+
+ private function updateOwsProxyUrl ($url) {
+ // is OWS proxy URL?
+ if (wms::isOwsProxyUrl($url)) {
+
+ // No WMS id could be found
+ if (!$this->wms_id) {
+ $e = new mb_notice("No WMS id could be found!");
+ return $url;
+ }
+ // Update session id in OWS proxy URL
+ $new_proxy_url = $this->replaceSessionIdInOwsProxyUrl($url);
+
+ // If new url is a valid proxy URL, return true
+ if ($this->isOwsProxyUrl($new_proxy_url)) {
+ return $new_proxy_url;
+ }
+ else {
+// $e = new mb_notice("new URL is not an OWS proxy URL!");
+ }
+ // new URL is not an OWS proxy URL;
+ // some error must have occured.
+ // no update
+ return $url;
+ }
+ // no OWS proxy URL, no update necessary
+// $e = new mb_notice("URL is not an OWS proxy URL!");
+ return $url;
+ }
+
+ function updateAllOwsProxyUrls () {
+ $wmsId = $this->wms_id;
+
+ // if WMS id is unknown, try to
+ // find it via OWS proxy entry
+ //FIXME -Funktion berichtigen
+ if (!$wmsId) {
+ $md5 = wms::getHashFromOwsProxyUrl($url);
+ if ($md5) {
+ $wmsId = $this->getWmsIdByOwsProxyHash($md5);
+ if (!is_null($wmsId)) {
+ $this->wms_id = $wmsId;
+ }
+ }
+ }
+
+ $this->wms_getmap =
+ $this->updateOwsProxyUrl($this->wms_getmap);
+ $this->wms_getfeatureinfo =
+ $this->updateOwsProxyUrl($this->wms_getfeatureinfo);
+ $this->wms_getlegendurl =
+ $this->updateOwsProxyUrl($this->wms_getlegendurl);
+
+ for ($i = 0; $i < count($this->objLayer); $i++) {
+ for ($j = 0; $j < count($this->objLayer[$i]->layer_style); $j++) {
+ $this->objLayer[$i]->layer_style[$j]["legendurl"] =
+ $this->updateOwsProxyUrl($this->objLayer[$i]->layer_style[$j]["legendurl"]);
+ }
+ }
+ }
+
+ public static function getConjunctionCharacter ($url) {
+ if (mb_strpos($url, "?") !== false) {
+ if (mb_substr($url, mb_strlen($url)-1, 1) == "?") {
+ return "";
+ }
+ else if (mb_substr($url, mb_strlen($url)-1, 1) == "&"){
+ return "";
+ }
+ else {
+ return "&";
+ }
+ }
+ else {
+ return "?";
+ }
+ return "";
+ }
+
+ function createOlObjFromWMS($base){
+ if(!$this->wms_title || $this->wms_title == ""){
+ echo "alert('Error: no valid capabilities-document !!');";
+ die; exit;
+ }
+ // wms_title and abstract have previously been urlencoded
+ // this solution may not yet be the ultimate one
+
+ $add_wms_string = "var wms_".$this->wms_id." = new OpenLayers.Layer.WMS(";
+ // WMS-title
+ $add_wms_string .= "'" . addslashes($this->wms_title) . "',";
+ // Base-URL of service
+ $add_wms_string .= "'" . $this->wms_getmap ."',";
+ // Additional URL params
+ $add_wms_string .= "{layers:'";
+ for($i=1;$i<count($this->objLayer);$i++){
+ $add_wms_string .= addslashes($this->objLayer[$i]->layer_name);
+ if($i!=count($this->objLayer)-1) {
+ $add_wms_string .= ",";
+ }
+ }
+ $add_wms_string .= "',";
+ // This is hardcoded, exactly as for Mapbender WMS
+ $add_wms_string .= "transparent: 'true',";
+ $add_wms_string .= "format: '".$this->gui_wms_mapformat."'},";
+ // OpenLayers-Layer options
+ $add_wms_string .= "{";
+ $add_wms_string .= "transitionEffect:'resize',";
+ $add_wms_string .= "buffer:1.3,";
+ $add_wms_string .= "singleTile:true,";
+ // baselayer?
+ if($base) {
+ $add_wms_string .= "isBaseLayer:true,";
+ } else {
+ $add_wms_string .= "isBaseLayer:false,";
+ }
+ // visible or not?
+ if($this->gui_wms_visible=="1") {
+ $add_wms_string .= "visibility:true,";
+ } else {
+ $add_wms_string .= "visibility:false,";
+ }
+ // initial transparency
+ $add_wms_string .= "opacity:" . strval(round($this->gui_wms_opacity/100, 2));
+
+ $add_wms_string .= "}";
+ $add_wms_string .= ");";
+
+ // TODO why ol_map
+ $add_wms_string .= "ol_map.addLayer(wms_".$this->wms_id.");";
+ echo $add_wms_string;
+ }
+
+ /**
+ * Compares this WMS to another WMS.
+ *
+ * @return boolean false, if
+ * - the capabilities URLs don't match
+ * - the layer count is different
+ * - the layer names are different
+ *
+ * @param $anotherWms wms this is just another WMS object
+ */
+ public function equals ($anotherWms) {
+ // If the getMap URLs are not equal, the WMS are not equal.
+ if ($this->wms_getmap != $anotherWms->wms_getmap) {
+// $e = new mb_notice($this . " != " . $anotherWms . " (getMap URL)");
+ return false;
+ }
+
+ // If the layer count is different, the WMS are not equal.
+ if (count($this->objLayer) != count($anotherWms->objLayer)) {
+// $e = new mb_notice($this . " != " . $anotherWms . " (layer count: " . count($this->objLayer) . ":" . count($anotherWms->objLayer). ")");
+ return false;
+ }
+
+ // If the layer names are different, the WMS are not equal.
+ for ($i = 0; $i < count($this->objLayer); $i++) {
+ $name1 = $this->objLayer[$i]->layer_name;
+ $name2 = $anotherWms->objLayer[$i]->layer_name;
+
+ if ($name1 != $name2) {
+// $e = new mb_notice($this . " != " . $anotherWms . " (layer names, " . $name1 . " vs. " . $name2 . ")");
+ return false;
+ }
+ }
+// $e = new mb_notice($this . " == " . $anotherWms);
+ return true;
+ }
+
+ /**
+ * The other WMS must be the same as this WMS, but with different
+ * application settings. These application settings are copied,
+ * the local settings are overwritten.
+ *
+ * @return boolean true if the settings could be copied; false
+ * when an error occured.
+ * @param $anotherWms wms The same WMS with possibly other settings
+ */
+/*
+ public function copyConfiguration ($anotherWms) {
+ if (!$this->equals($anotherWms)) {
+ $e = new mb_exception("class_wms.php: copyConfiguration(): parameters cannot be copied, it's a different WMS.");
+ return false;
+ }
+ for ($i = 0; $i < count($this->objLayer); $i++) {
+ $myCurrentLayer = $this->objLayer[$i];
+ $theirCurrentLayer = $anotherWms->objLayer[$i];
+
+ $myCurrentLayer->gui_layer_selectable = $theirCurrentLayer->gui_layer_selectable;
+ $myCurrentLayer->gui_layer_visible = $theirCurrentLayer->gui_layer_visible;
+ $myCurrentLayer->gui_layer_queryable = $theirCurrentLayer->gui_layer_queryable;
+ $myCurrentLayer->gui_layer_querylayer = $theirCurrentLayer->gui_layer_querylayer;
+ $myCurrentLayer->gui_layer_style = $theirCurrentLayer->gui_layer_style;
+ }
+ }
+*/
+
+ /**
+ * Removes duplicate WMS from an array of WMS. To find duplicates,
+ * two WMS are compared via equals().
+ *
+ * @return wms[]
+ * @param $wmsArray wms[]
+ */
+ public static function merge ($wmsArray) {
+ $e = new mb_notice("before: " . implode(", ", $wmsArray));
+ if (!is_array($wmsArray)) {
+ $e = new mb_exception("class_wms.php: merge(): parameter is NOT an array.");
+ return array();
+ }
+ if (count($wmsArray) == 0) {
+ $e = new mb_exception("class_wms.php: merge(): parameter is an EMPTY array.");
+ return array();
+ }
+
+ $newWmsArray = array();
+
+ while (count($wmsArray) > 0) {
+ $currentWms = array_pop($wmsArray);
+
+ $isNewWms = true;
+
+ if (get_class($currentWms) != "wms") {
+ $e = new mb_exception("class_wms.php: merge(): current WMS is not a WMS object, but a " . get_class($currentWms));
+ }
+ else {
+ for ($i = 0; $i < count($newWmsArray) && $isNewWms; $i++) {
+ if ($currentWms->equals($newWmsArray[$i])) {
+ $isNewWms = false;
+ }
+ }
+ if ($isNewWms) {
+// $e = new mb_notice("adding WMS " . $currentWms);
+ array_push($newWmsArray, $currentWms);
+ }
+ }
+ }
+ // reversal of the array, because the elements were popped
+ // from another array before.
+// $e = new mb_notice("after: " . implode(", ", array_reverse($newWmsArray)));
+ return array_reverse($newWmsArray);
+ }
+
+ private function formatExists ($type, $format) {
+ for ($i = 0; $i < count($this->data_type); $i++) {
+ if ($type == $this->data_type[$i] && $format == $this->data_format[$i]) {
+ $e = new mb_warning("WMS format already exists ($type, $format). Violation of WMS spec. Ignoring this WMS format.");
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public function __toString () {
+ return $this->wms_title;
+ }
+
+ function createObjFromXML($url){
+ if (func_num_args() == 2) { //new for HTTP Authentication
+ $auth = func_get_arg(1);
+ $x = new connector($url,$auth);
+ }
+ else {
+ $x = new connector($url);
+ }
+ $data = $x->file;
+ if ($data=='401') {
+ echo "<br>HTTP Error:<b>".$data." - Authorization required. This seems to be a service which needs HTTP Authentication!</b><br>";
+ }
+ if(!$data){
+ $this->wms_status = false;
+ return false;
+ }
+ else {
+ $this->wms_status = true;
+ }
+
+ $values = null;
+ $tags = null;
+ $admin = new administration();
+ $this->wms_getcapabilities_doc = $data;
+ $this->wms_upload_url = $url;
+
+ $this->wms_id = "";
+ $parser = xml_parser_create("");
+ xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+ xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+ xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+ xml_parse_into_struct($parser,$data,$values,$tags);
+
+ $code = xml_get_error_code($parser);
+ if ($code) {
+ $line = xml_get_current_line_number($parser);
+ $mb_exception = new mb_exception(xml_error_string($code) . " in line " . $line);
+ }
+
+ xml_parser_free($parser);
+
+ $section = null;
+ $format = null;
+ $cnt_format = 0;
+ $parent = array();
+ $myParent = array();
+ $cnt_layer = -1;
+ $request = null;
+ $layer_style = array();
+ $cnt_styles = -1;
+
+ $this->wms_getfeatureinfo = "";
+ $this->gui_wms_featureinfoformat = "";
+
+ foreach ($values as $element) {
+ if(mb_strtoupper($element[tag]) == "WMT_MS_CAPABILITIES" && $element[type] == "open"){
+ $this->wms_version = $element[attributes][version];
+ }
+ if(mb_strtoupper($element[tag]) == "TITLE" && $element[level] == '3'){
+ $this->wms_title = $this->stripEndlineAndCarriageReturn($element[value]);
+ }
+ if(mb_strtoupper($element[tag]) == "ABSTRACT" && $element[level] == '3'){
+ $this->wms_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+ }
+ if(mb_strtolower($element[tag]) == "fees"){
+ $this->fees = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "accessconstraints"){
+ $this->accessconstraints = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "contactperson"){
+ $this->contactperson = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "contactposition"){
+ $this->contactposition = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "contactorganization"){
+ $this->contactorganization = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "address"){
+ $this->address = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "city"){
+ $this->city = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "stateorprovince"){
+ $this->stateorprovince = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "postcode"){
+ $this->postcode = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "country"){
+ $this->country = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "contactvoicetelephone"){
+ $this->contactvoicetelephone = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "contactfacsimiletelephone"){
+ $this->contactfacsimiletelephone = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "contactelectronicmailaddress"){
+ $this->contactelectronicmailaddress = $element[value];
+ }
+ if(mb_strtolower($element[tag]) == "keyword" && $section != 'layer'){
+ $this->wms_keyword[count($this->wms_keyword)] = $element[value];
+ }
+
+ /*map section*/
+ if($this->wms_version == "1.0.0"){
+ if(mb_strtoupper($element[tag]) == "MAP" && $element[type] == "open"){
+ $section = "map";
+ }
+ if($section == "map" && mb_strtoupper($element[tag]) == "GET"){
+ $this->wms_getmap = $element[attributes][onlineResource];
+ }
+ if($section == "map" && mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+ $format = "map";
+ }
+ if(mb_strtoupper($element[tag]) != "FORMAT" && $section == "map" && $format == "map"){
+ if (!$this->formatExists("map", trim($element[tag]))) {
+ $this->data_type[$cnt_format] = "map";
+ $this->data_format[$cnt_format] = trim($element[tag]);
+ $cnt_format++;
+ }
+ }
+ if(mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+ $format = "";
+ }
+ if(mb_strtoupper($element[tag]) == "MAP" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ else{
+ if(mb_strtoupper($element[tag]) == "GETMAP" && $element[type] == "open"){
+ $section = "map";
+ }
+ if($section == "map" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+ $request = "get";
+ }
+ if($section == "map" && $request == "get" && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+ $this->wms_getmap = $element[attributes]["xlink:href"];
+ }
+ if($section == "map" && mb_strtoupper($element[tag]) == "FORMAT"){
+ if (!$this->formatExists("map", trim($element[value]))) {
+ $this->data_type[$cnt_format] = "map";
+ $this->data_format[$cnt_format] = trim($element[value]);
+ $cnt_format++;
+ }
+ }
+ if($section == "map" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+ $request = "";
+ }
+ if(mb_strtoupper($element[tag]) == "GETMAP" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ /*capabilities section*/
+ if($this->wms_version == "1.0.0"){
+ if(mb_strtoupper($element[tag]) == "CAPABILITIES" && $element[type] == "open"){
+ $section = "capabilities";
+ }
+ if($section == "capabilities" && mb_strtoupper($element[tag]) == "GET"){
+ $this->wms_getcapabilities = $element[attributes][onlineResource];
+ }
+ if(mb_strtoupper($element[tag]) == "CAPABILITIES" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ else{
+ if(mb_strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "open"){
+ $section = "capabilities";
+ }
+ if($section == "capabilities" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+ $request = "get";
+ }
+ if($section == "capabilities" && $request == "get" && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+ $this->wms_getcapabilities = $element[attributes]["xlink:href"];
+ }
+ if($section == "capabilities" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+ $request = "";
+ }
+ if(mb_strtoupper($element[tag]) == "GETCAPABILITIES" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ /*featureInfo section*/
+ if($this->wms_version == "1.0.0"){
+ if(mb_strtoupper($element[tag]) == "FEATUREINFO" && $element[type] == "open"){
+ $section = "featureinfo";
+ }
+ if($section == "featureinfo" && mb_strtoupper($element[tag]) == "GET"){
+ $this->wms_getfeatureinfo = $element[attributes][onlineResource];
+ }
+ if($section == "featureinfo" && mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+ $format = "featureinfo";
+ }
+ if(mb_strtoupper($element[tag]) != "FORMAT" && $section == "featureinfo" && $format == "featureinfo"){
+ if (!$this->formatExists("featureinfo", trim($element[tag]))) {
+ $this->data_type[$cnt_format] = "featureinfo";
+ $this->data_format[$cnt_format] = trim($element[tag]);
+ $cnt_format++;
+ }
+ }
+ if(mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+ $format = "";
+ }
+ if(mb_strtoupper($element[tag]) == "FEATUREINFO" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ else{
+ if(mb_strtoupper($element[tag]) == "GETFEATUREINFO" && $element[type] == "open"){
+ $section = "featureinfo";
+ }
+ if($section == "featureinfo" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+ $request = "get";
+ }
+ if($section == "featureinfo" && $request == "get" && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+ $this->wms_getfeatureinfo = $element[attributes]["xlink:href"];
+ }
+ if($section == "featureinfo" && mb_strtoupper($element[tag]) == "FORMAT"){
+ if (!$this->formatExists("featureinfo", trim($element[value]))) {
+ $this->data_type[$cnt_format] = "featureinfo";
+ $this->data_format[$cnt_format] = trim($element[value]);
+ $cnt_format++;
+ }
+ }
+ if($section == "featureinfo" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+ $request = "";
+ }
+ if(mb_strtoupper($element[tag]) == "GETFEATUREINFO" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ /*exception section*/
+ if($this->wms_version == "1.0.0"){
+ if(mb_strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "open"){
+ $section = "exception";
+ }
+ if($section == "exception" && mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "open"){
+ $format = "exception";
+ }
+ if(mb_strtoupper($element[tag]) != "FORMAT" && $section == "exception" && $format == "exception"){
+ $this->data_type[$cnt_format] = "exception";
+ $this->data_format[$cnt_format] = trim($element[tag]);
+ $cnt_format++;
+ }
+ if($section == "exception" && mb_strtoupper($element[tag]) == "FORMAT" && $element[type] == "close"){
+ $format = "";
+ }
+ if(mb_strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ else{
+ if(mb_strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "open"){
+ $section = "exception";
+ }
+ if($section == "exception" && mb_strtoupper($element[tag]) == "FORMAT"){
+ $this->data_type[$cnt_format] = "exception";
+ $this->data_format[$cnt_format] = trim($element[value]);
+ $cnt_format++;
+ }
+ if(mb_strtoupper($element[tag]) == "EXCEPTION" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ /*legend section*/
+ if($this->wms_version == "1.0.0"){
+
+ }
+ else{
+ if(mb_strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "open"){
+ $section = "legend";
+ }
+ if($section == "legend" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "open"){
+ $request = "get";
+ }
+ if($section == "legend" && $request == "get" && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+ $this->wms_getlegendurl = $element[attributes]["xlink:href"];
+ }
+ if($section == "legend" && mb_strtoupper($element[tag]) == "GET" && $element[type] == "close"){
+ $request = "";
+ }
+ if(mb_strtoupper($element[tag]) == "GETLEGENDGRAPHIC" && $element[type] == "close"){
+ $section = "";
+ }
+ }
+ /* sld section */
+ if(mb_strtoupper($element[tag]) == "USERDEFINEDSYMBOLIZATION" && $element[type] == "complete"){
+ $this->wms_supportsld = $element[attributes]["SupportSLD"];
+ $this->wms_userlayer = $element[attributes]["UserLayer"];
+ $this->wms_userstyle = $element[attributes]["UserStyle"];
+ $this->wms_remotewfs = $element[attributes]["RemoteWFS"];
+ }
+
+ /*layer section*/
+ if(mb_strtoupper($element[tag]) == "LAYER"){
+ $section = "layer";
+ if ($element[type] == "open") {
+ $cnt_epsg = -1;
+ $cnt_layer++;
+ $parent[$element[level]+1] = $cnt_layer;
+ $myParent[$cnt_layer]= $parent[$element[level]];
+ $this->addLayer($cnt_layer,$myParent[$cnt_layer]);
+ $this->objLayer[$cnt_layer]->layer_queryable = $element[attributes][queryable];
+ }
+ if ($element[type] == "close") {
+
+ }
+ }
+ /* attribution */
+ if(mb_strtoupper($element[tag]) == "ATTRIBUTION"){
+ if ($element[type] == "open") {
+ $section = "attribution";
+ }
+ if ($element[type] == "close") {
+ $section = "layer";
+ }
+ }
+ /* styles */
+ if(mb_strtoupper($element[tag]) == "STYLE"){
+ $section = "style";
+ if($cnt_layer != $layer_style){
+ $layer_style = $cnt_layer;
+ $cnt_styles = -1;
+ }
+ if ($element[type] == "open") {
+ $cnt_styles++;
+ }
+ if ($element[type] == "close") {
+ $section = "layer";
+ }
+ }
+ if($section == "style"){
+ if(mb_strtoupper($element[tag]) == "NAME"){
+ $this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["name"] = ($element[value] ? $element[value] : 'default');
+ }
+ if(mb_strtoupper($element[tag]) == "TITLE"){
+ $this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["title"] = ($element[value] ? $element[value] : '');
+ }
+ if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "open"){
+ $legendurl = true;
+ }
+ if($legendurl && mb_strtoupper($element[tag]) == "FORMAT"){
+ $this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurlformat"] = $element[value];
+ }
+ if($legendurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+ $this->objLayer[$cnt_layer]->layer_style[$cnt_styles]["legendurl"] = $element[attributes]["xlink:href"];
+ }
+ if(mb_strtoupper($element[tag]) == "LEGENDURL" && $element[type] == "close"){
+ $legendurl = false;
+ }
+ }
+ /* end of styles */
+ if($section == "layer"){
+ if(mb_strtoupper($element[tag]) == "NAME"){
+ $this->objLayer[$cnt_layer]->layer_name = $element[value];
+ }
+ if(mb_strtoupper($element[tag]) == "TITLE"){
+ $this->objLayer[$cnt_layer]->layer_title = $this->stripEndlineAndCarriageReturn($element[value]);
+ }
+ if(mb_strtoupper($element[tag]) == "ABSTRACT"){
+ $this->objLayer[$cnt_layer]->layer_abstract = $this->stripEndlineAndCarriageReturn($element[value]);
+ }
+ if(mb_strtoupper($element[tag]) == "KEYWORD"){
+ array_push($this->objLayer[$cnt_layer]->layer_keyword, trim($element[value]));
+ }
+ if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "open"){
+ $dataurl = true;
+ }
+ if($dataurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+ $this->objLayer[$cnt_layer]->layer_dataurl_href = $element[attributes]["xlink:href"];
+ }
+ if(mb_strtoupper($element[tag]) == "DATAURL" && $element[type] == "close"){
+ $dataurl = false;
+ }
+
+ if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "open"){
+ $metadataurl = true;
+ }
+ if($metadataurl && mb_strtoupper($element[tag]) == "ONLINERESOURCE"){
+ $this->objLayer[$cnt_layer]->layer_metadataurl = $element[attributes]["xlink:href"];
+ }
+ if(mb_strtoupper($element[tag]) == "METADATAURL" && $element[type] == "close"){
+ $metadataurl = false;
+ }
+
+ if(mb_strtoupper($element[tag]) == "SRS"){
+ // unique srs only, see http://www.mapbender.org/index.php/Arrays_with_unique_entries
+ $this->wms_srs = array_keys(array_flip(array_merge($this->wms_srs, explode(" ", strtoupper($element[value])))));
+ }
+ if(mb_strtoupper($element[tag]) == "LATLONBOUNDINGBOX"){
+ $cnt_epsg++;
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["epsg"] = "EPSG:4326";
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["minx"] = $element[attributes][minx];
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["miny"] = $element[attributes][miny];
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxx"] = $element[attributes][maxx];
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxy"] = $element[attributes][maxy];
+ }
+ if(mb_strtoupper($element[tag]) == "BOUNDINGBOX" && $element[attributes][SRS] != "EPSG:4326"){
+ $cnt_epsg++;
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["epsg"] = $element[attributes][SRS];
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["minx"] = $element[attributes][minx];
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["miny"] = $element[attributes][miny];
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxx"] = $element[attributes][maxx];
+ $this->objLayer[$cnt_layer]->layer_epsg[$cnt_epsg]["maxy"] = $element[attributes][maxy];
+ // a default epsg for mapbender
+ if($cnt_layer == 0 && $this->default_epsg == 0 && mb_strlen(trim($element[attributes][SRS]))>= 10){
+ $this->default_epsg = $cnt_epsg;
+ }
+ }
+ if(mb_strtoupper($element[tag]) == "SCALEHINT"){
+ if($element[attributes][max]>1000) $max = 0; else $max = $element[attributes][max];
+ if($element[attributes][min]>1000) $min = 0; else $min = $element[attributes][min];
+ $this->objLayer[$cnt_layer]->layer_minscale = round(($min * 2004.3976484406788493955738891127));
+ $this->objLayer[$cnt_layer]->layer_maxscale = round(($max * 2004.3976484406788493955738891127));
+ }
+ }
+ else {
+ continue;
+ }
+ }
+ if(!$this->wms_title || $this->wms_title == "" || !$this->wms_getmap || $this->wms_getmap == ""){
+ $this->wms_status = false;
+ $this->optimizeWMS();
+ $e = new mb_exception("class_wms: createObjFromXML: WMS " . $url . " could not be loaded.");
+ return false;
+ }
+ else{
+ $this->wms_status = true;
+ $this->optimizeWMS();
+ $e = new mb_notice("class_wms: createObjFromXML: WMS " . $url . " has been loaded successfully.");
+ return true;
+ }
+ }
+ /**
+ * private function
+ */
+ function optimizeWMS() {
+ /*define defaults for wms-version 1.0.0*/
+ $map_default_ok = false;
+ $featureinfo_default_ok = false;
+ $exception_default_ok = false;
+ if($this->wms_version == "1.0.0"){
+ $map_default = "PNG";
+ $featureinfo_default = "MIME";
+ $exception_default = "INIMAGE";
+ }
+ /*define defaults for wms-version 1.1.0 and 1.1.1*/
+ else{
+ $map_default = "image/png";
+ $featureinfo_default = "text/html";
+ $exception_default = "application/vnd.ogc.se_inimage";
+ }
+ #some default
+ $this->gui_wms_visible = 1;
+ $this->gui_wms_opacity = 100;
+ /*if the rootlayer has no epsg...*/
+ if($this->objLayer[0]->layer_epsg[0]["epsg"] == ""){
+ $this->objLayer[0]->layer_epsg = $this->objLayer[1]->layer_epsg;
+ for($i=0;$i<count($this->objLayer[0]->layer_epsg);$i++){
+ for($j=1; $j<count($this->objLayer); $j++){
+ if($this->objLayer[0]->layer_epsg[$i]["epsg"] == $this->objLayer[$j]->layer_epsg[$i]["epsg"]){
+ if($this->objLayer[$j]->layer_epsg[$i]["minx"]<$this->objLayer[0]->layer_epsg[$i]["minx"]){
+ $this->objLayer[0]->layer_epsg[$i]["minx"] = $this->objLayer[$j]->layer_epsg[$i]["minx"];
+ }
+ if($this->objLayer[$j]->layer_epsg[$i]["miny"]<$this->objLayer[0]->layer_epsg[$i]["miny"]){
+ $this->objLayer[0]->layer_epsg[$i]["miny"] = $this->objLayer[$j]->layer_epsg[$i]["miny"];
+ }
+ if($this->objLayer[$j]->layer_epsg[$i]["maxx"]>$this->objLayer[0]->layer_epsg[$i]["maxx"]){
+ $this->objLayer[0]->layer_epsg[$i]["maxx"] = $this->objLayer[$j]->layer_epsg[$i]["maxx"];
+ }
+ if($this->objLayer[$j]->layer_epsg[$i]["maxy"]>$this->objLayer[0]->layer_epsg[$i]["maxy"]){
+ $this->objLayer[0]->layer_epsg[$i]["maxy"] = $this->objLayer[$j]->layer_epsg[$i]["maxy"];
+ }
+ }
+ }
+ }
+ }
+ for($i=0;$i<count($this->objLayer);$i++){
+ if(count($this->objLayer[$i]->layer_epsg) == 0 && count($this->objLayer[0]->layer_epsg) > 0){
+ $this->objLayer[$i]->layer_epsg = $this->objLayer[0]->layer_epsg;
+ }
+ if(!is_int($this->objLayer[$i]->layer_parent)){
+ $this->objLayer[$i]->layer_abstract = $this->wms_abstract;
+ for ($r = 0; $r < count($this->wms_keyword); $r++) {
+ array_push($this->objLayer[$i]->layer_keyword, trim($this->wms_keyword[$r]));
+ }
+ }
+ if($this->objLayer[$i]->layer_name == ""){
+ $this->objLayer[$i]->layer_name = $this->objLayer[$i]->layer_title;
+ }
+ if($this->objLayer[$i]->layer_minscale == ""){
+ $this->objLayer[$i]->layer_minscale = 0;
+ }
+ if($this->objLayer[$i]->layer_maxscale == ""){
+ $this->objLayer[$i]->layer_maxscale = 0;
+ }
+ if($this->objLayer[$i]->layer_queryable == ""){
+ $this->objLayer[$i]->layer_queryable = 0;
+ }
+ $this->objLayer[$i]->gui_layer_minscale = $this->objLayer[$i]->layer_minscale;
+ $this->objLayer[$i]->gui_layer_maxscale = $this->objLayer[$i]->layer_maxscale;
+ }
+ for($i=0;$i<count($this->data_format);$i++){
+ if(mb_strtolower($this->data_type[$i]) == 'map' && mb_strtoupper($this->data_format[$i]) == mb_strtoupper($map_default)){
+ $this->gui_wms_mapformat = mb_strtolower($map_default);
+ $map_default_ok = true;
+ }
+ if(mb_strtolower($this->data_type[$i]) == 'featureinfo' && mb_strtoupper($this->data_format[$i]) == mb_strtoupper($featureinfo_default)){
+ $this->gui_wms_featureinfoformat = mb_strtolower($featureinfo_default);
+ $featureinfo_default_ok = true;
+ }
+ if(mb_strtolower($this->data_type[$i]) == 'exception' && mb_strtolower($this->data_format[$i]) == mb_strtolower($exception_default)){
+ $this->gui_wms_exceptionformat = mb_strtolower($exception_default);
+ $exception_default_ok = true;
+ }
+ }
+ if($map_default_ok == false){
+ for($i=0;$i<count($this->data_format);$i++){
+ if(mb_strtolower($this->data_type[$i]) == "map" ){$this->gui_wms_mapformat = $this->data_format[$i]; break;}
+ }
+ }
+ if($featureinfo_default_ok == false){
+ for($i=0;$i<count($this->data_format);$i++){
+ if(mb_strtolower($this->data_type[$i]) == "featureinfo" ){$this->gui_wms_featureinfoformat = $this->data_format[$i]; break;}
+ }
+ }
+ if($exception_default_ok == false){
+ for($i=0;$i<count($this->data_format);$i++){
+ if(mb_strtolower($this->data_type[$i]) == "exception" ){$this->gui_wms_exceptionformat = $this->data_format[$i]; break;}
+ }
+ }
+
+ if(count($this->objLayer[0]->layer_epsg)>1){
+ $this->gui_wms_epsg = $this->objLayer[0]->layer_epsg[$this->default_epsg][epsg];
+ }
+ else{
+ $this->gui_wms_epsg = $this->objLayer[0]->layer_epsg[0][epsg];
+ }
+ /*the queryable layers*/
+ for($i=0; $i<count($this->objLayer); $i++){
+ if($this->objLayer[$i]->layer_queryable == 1){
+ $this->objLayer[$i]->gui_layer_queryable = 1;
+ }
+ else{
+ $this->objLayer[$i]->gui_layer_queryable = 0;
+ }
+ }
+ for($i=0; $i<count($this->objLayer); $i++){
+ $this->objLayer[$i]->layer_pos=$i;
+ }
+
+ /* fill sld variables when empty */
+ if($this->wms_supportsld == ""){
+ $this->wms_supportsld = 0;
+ }
+ if($this->wms_userlayer == ""){
+ $this->wms_userlayer = 0;
+ }
+ if($this->wms_userstyle == ""){
+ $this->wms_userstyle = 0;
+ }
+ if($this->wms_remotewfs == ""){
+ $this->wms_remotewfs = 0;
+ }
+ }
+
+ function displayWMS(){
+ echo "<br>id: " . $this->wms_id . " <br>";
+ echo "version: " . $this->wms_version . " <br>";
+ echo "title: " . $this->wms_title . " <br>";
+ echo "abstract: " . $this->wms_abstract . " <br>";
+ echo "maprequest: " . $this->wms_getmap . " <br>";
+ echo "capabilitiesrequest: " . $this->wms_getcapabilities . " <br>";
+ echo "featureinforequest: " . $this->wms_getfeatureinfo . " <br>";
+ echo "gui_wms_mapformat: " . $this->gui_wms_mapformat . " <br>";
+ echo "gui_wms_featureinfoformat: " . $this->gui_wms_featureinfoformat . " <br>";
+ echo "gui_wms_exceptionformat: " . $this->gui_wms_exceptionformat . " <br>";
+ echo "gui_wms_epsg: " . $this->gui_wms_epsg . " <br>";
+ echo "wms_srs: " . implode(", ", $this->wms_srs) . " <br>";
+ echo "gui_wms_visible: " . $this->gui_wms_visible . " <br>";
+ echo "gui_wms_opacity: " . $this->gui_wms_opacity . " <br>";
+ echo "support_sld: " . $this->wms_supportsld . " <br>";
+
+ for($i=0; $i<count($this->data_type);$i++){
+ echo $this->data_type[$i]. " -> ".$this->data_format[$i]. "<br>";
+ }
+ for($i=0; $i<count($this->objLayer); $i++){
+ echo "<hr>";
+ echo "id: <b>".$this->objLayer[$i]->layer_id ."</b> parent: <b>".$this->objLayer[$i]->layer_parent."</b> name: <b>".$this->objLayer[$i]->layer_name;
+ echo "</b> title: <b>".$this->objLayer[$i]->layer_title. "</b> queryable: <b>".$this->objLayer[$i]->layer_queryable."</b> minScale: <b>". $this->objLayer[$i]->layer_minscale."</b> maxScale: <b>".$this->objLayer[$i]->layer_maxscale."</b>";
+ echo "<br>dataurl: <b>".$this->objLayer[$i]->layer_dataurl_href. "</b>";
+ echo "<br>metadataurl: <b>".$this->objLayer[$i]->layer_metadataurl. "</b>";
+ echo "<table border='1'>";
+ for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+ echo "<tr><td>".$this->objLayer[$i]->layer_epsg[$j][epsg]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][minx]."</td>";
+ echo "<td>".$this->objLayer[$i]->layer_epsg[$j][miny]."</td><td>".$this->objLayer[$i]->layer_epsg[$j][maxx]."</td>";
+ echo "<td>".$this->objLayer[$i]->layer_epsg[$j][maxy]."</td></tr>";
+ }
+ echo "</table>";
+ echo "layerstyle:";
+ echo "<table border='1'>";
+ echo "<tr><td>name</td><td>title</td><td>legendurl</td><td>legendurlformat</td></tr>";
+ for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+ echo "<tr><td>".$this->objLayer[$i]->layer_style[$j][name]."</td><td>".$this->objLayer[$i]->layer_style[$j][title]."</td><td>".$this->objLayer[$i]->layer_style[$j][legendurl]."</td><td>".$this->objLayer[$i]->layer_style[$j][legendurlformat]."</td></tr>";
+ }
+ echo "</table>";
+ echo "<hr>";
+ echo "<hr>";
+ }
+ }
+ function addLayer($id,$parent){
+ $this->objLayer[count($this->objLayer)] = new layer($id,$parent);
+ }
+ /**
+ * private function
+ */
+ function stripEndlineAndCarriageReturn($string) {
+ return preg_replace("/\n/", "", preg_replace("/\r/", " ", $string));
+ }
+ function createJsObjFromWMS($parent=0){
+ echo $this->createJsObjFromWMS_($parent);
+ }
+
+
+ function newLayer ($currentLayer, $currentExtent) {
+ $pos = $currentLayer["extension"]["LAYER_POS"];
+ $parent = $currentLayer["extension"]["LAYER_PARENT"];
+ $this->addLayer($pos, $parent);
+
+ // set layer data
+ $layerIndex = count($this->objLayer) - 1;
+ $newLayer = $this->objLayer[$layerIndex];
+ $newLayer->layer_uid = $currentLayer["extension"]["LAYER_ID"];
+ $newLayer->layer_name = $currentLayer["name"];
+ $newLayer->layer_title = $currentLayer["title"];
+ $newLayer->layer_dataurl_href = $currentLayer["dataurl"];
+ $newLayer->layer_pos = $currentLayer["extension"]["LAYER_POS"];
+ $newLayer->layer_queryable = $currentLayer["queryable"];
+ $newLayer->layer_minscale = $currentLayer["extension"]["MINSCALE"];
+ $newLayer->layer_maxscale = $currentLayer["extension"]["MAXSCALE"];
+ $newLayer->layer_metadataurl = $currentLayer["metadataurl"];
+ $newLayer->gui_layer_wms_id = $currentLayer["extension"]["WMS_ID"];
+ $newLayer->gui_layer_status = $currentLayer["extension"]["GUI_STATUS"];
+ $newLayer->gui_layer_style = ""; // TODO: Add correct data
+ $newLayer->gui_layer_selectable = $currentLayer["extension"]["GUI_SELECTABLE"];
+ if (isset($currentLayer["extension"]["OVERVIEWHIDDEN"])) {
+ $newLayer->gui_layer_visible = ($currentLayer["extension"]["OVERVIEWHIDDEN"] === "1") ? false : true;
+ }
+ else {
+ $newLayer->gui_layer_visible = $currentLayer["visible"];
+ }
+ if (isset($currentLayer["extension"]["WFSFEATURETYPE"])) {
+ $newLayer->gui_layer_wfs_featuretype = strval($currentLayer["extension"]["WFSFEATURETYPE"]);
+ }
+ else {
+ $newLayer->gui_layer_wfs_featuretype = "";
+ }
+ $newLayer->gui_layer_queryable = $currentLayer["extension"]["GUI_QUERYABLE"];
+ $newLayer->gui_layer_querylayer = $currentLayer["extension"]["QUERYLAYER"];
+ $newLayer->gui_layer_minscale = $currentLayer["extension"]["GUI_MINSCALE"];
+ $newLayer->gui_layer_maxscale = $currentLayer["extension"]["GUI_MAXSCALE"];
+ $newLayer->layer_abstract = $currentLayer["abstract"];
+
+ //
+ // set layer epsg
+ //
+ $tmpEpsgArray= array();
+ $newLayer->layer_epsg = array();
+ if ($currentLayer["extension"]["EPSG"]) {
+ $layerEpsgArray = array();
+ $layerMinXArray = array();
+ $layerMinYArray = array();
+ $layerMaxXArray = array();
+ $layerMaxYArray = array();
+ if (!is_array($currentLayer["extension"]["EPSG"])) {
+ $layerEpsgArray[0] = $currentLayer["extension"]["EPSG"];
+ $layerMinXArray[0] = $currentLayer["extension"]["MINX"];
+ $layerMinYArray[0] = $currentLayer["extension"]["MINY"];
+ $layerMaxXArray[0] = $currentLayer["extension"]["MAXX"];
+ $layerMaxYArray[0] = $currentLayer["extension"]["MAXY"];
+ }
+ else {
+ $layerEpsgArray = $currentLayer["extension"]["EPSG"];
+ $layerMinXArray = $currentLayer["extension"]["MINX"];
+ $layerMinYArray = $currentLayer["extension"]["MINY"];
+ $layerMaxXArray = $currentLayer["extension"]["MAXX"];
+ $layerMaxYArray = $currentLayer["extension"]["MAXY"];
+ }
+
+ for ($i=0; $i < count($layerEpsgArray); $i++) {
+ $currentLayerEpsg = array();
+ $currentLayerEpsg["epsg"] = $layerEpsgArray[$i];
+ $tmpEpsgArray[]= $layerEpsgArray[$i];
+ if ($layerMinXArray[$i] == 0
+ && $layerMinYArray[$i] == 0
+ && $layerMaxXArray[$i] == 0
+ && $layerMaxYArray[$i] == 0
+ ) {
+ $currentLayerEpsg["minx"] = null;
+ $currentLayerEpsg["miny"] = null;
+ $currentLayerEpsg["maxx"] = null;
+ $currentLayerEpsg["maxy"] = null;
+ }
+ else {
+ $currentLayerEpsg["minx"] = floatval($layerMinXArray[$i]);
+ $currentLayerEpsg["miny"] = floatval($layerMinYArray[$i]);
+ $currentLayerEpsg["maxx"] = floatval($layerMaxXArray[$i]);
+ $currentLayerEpsg["maxy"] = floatval($layerMaxYArray[$i]);
+ }
+ array_push($newLayer->layer_epsg, $currentLayerEpsg);
+ }
+ }
+ for ($i = 0; $i < count($currentLayer["epsg"]); $i++) {
+ if (!in_array($currentLayer["epsg"][$i], $tmpEpsgArray)) {
+ $newLayer->layer_epsg[]= array(
+ "epsg" => $currentLayer["epsg"][$i],
+ "minx" => null,
+ "miny" => null,
+ "maxx" => null,
+ "maxy" => null
+ );
+ }
+ }
+
+ //
+ // set layer style
+ //
+ for ($i = 0; $i < count($currentLayer["style"]); $i++) {
+ $layerStyleIndex = count($newLayer->gui_layer_style) - 1;
+ $newLayer->layer_style[$layerStyleIndex] = array();
+ $newLayer->layer_style[$layerStyleIndex]["name"] = $currentLayer["style"][$i]["name"];
+ $newLayer->layer_style[$layerStyleIndex]["title"] = $currentLayer["style"][$i]["title"];
+ $newLayer->layer_style[$layerStyleIndex]["legendurl"] = $currentLayer["style"][$i]["legendurl"];
+ $newLayer->layer_style[$layerStyleIndex]["legendurl_format"] = $currentLayer["style"][$i]["legendurl_type"];
+ }
+ }
+
+ function createJsObjFromWMS_($parent=0){
+
+ $str = "";
+ if(!$this->wms_title || $this->wms_title == ""){
+ $str .= "alert('Error: no valid capabilities-document !!');";
+ die; exit;
+ }
+ if($parent){
+ $str .= "parent.";
+ }
+ // wms_title and abstract have previously been urlencoded
+ // this solution may not yet be the ultimate one
+
+ $add_wms_string = "add_wms(" .
+ "'" . $this->wms_id ."'," .
+ "'" . $this->wms_version ."'," .
+ "'" . addslashes($this->wms_title) . "'," .
+ "'" . addslashes($this->wms_abstract) ."'," .
+ "'" . $this->wms_getmap ."'," .
+ "'" . $this->wms_getfeatureinfo ."'," .
+ "'" . $this->wms_getlegendurl ."'," .
+ "'" . $this->wms_filter ."'," .
+ "'" . $this->gui_wms_mapformat . "'," .
+ "'" . $this->gui_wms_featureinfoformat . "'," .
+ "'" . $this->gui_wms_exceptionformat . "'," .
+ "'" . $this->gui_wms_epsg ."'," .
+ "'" . $this->gui_wms_visible ."'," .
+ "'" . $this->gui_wms_opacity ."'," .
+ "'" . $this->gui_wms_sldurl ."" .
+ "');";
+ $str .= $add_wms_string;
+
+ for($i=0;$i<count($this->data_format);$i++){
+ if($parent){
+ $str .= "parent.";
+ }
+ $str .= "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');";
+ }
+ for($i=0; $i<count($this->objLayer); $i++){
+ if($parent){
+ $str .= "parent.";
+ }
+ $str .= "wms_add_layer('".
+ $this->objLayer[$i]->layer_parent ."','".
+ $this->objLayer[$i]->layer_uid ."','".
+ addslashes($this->objLayer[$i]->layer_name) . "','".
+ addslashes($this->objLayer[$i]->layer_title) ."','".
+ $this->objLayer[$i]->layer_dataurl_href ."','".
+ $this->objLayer[$i]->layer_pos ."','".
+ $this->objLayer[$i]->layer_queryable ."','".
+ $this->objLayer[$i]->layer_minscale . "','".
+ $this->objLayer[$i]->layer_maxscale ."','".
+ $this->objLayer[$i]->layer_metadataurl ."','".
+ $this->objLayer[$i]->gui_layer_wms_id ."','".
+ $this->objLayer[$i]->gui_layer_status ."','".
+ $this->objLayer[$i]->gui_layer_style ."','".
+ $this->objLayer[$i]->gui_layer_selectable ."','".
+ $this->objLayer[$i]->gui_layer_visible ."','".
+ $this->objLayer[$i]->gui_layer_queryable ."','".
+ $this->objLayer[$i]->gui_layer_querylayer ."','".
+ $this->objLayer[$i]->gui_layer_minscale ."','".
+ $this->objLayer[$i]->gui_layer_maxscale ."','".
+ $this->objLayer[$i]->gui_layer_wfs_featuretype ."');";
+
+ for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+ $currentEpsg = $this->objLayer[$i]->layer_epsg[$j];
+ if($i==0){
+ if($parent){
+ $str .= "parent.";
+ }
+ $str .= "wms_addSRS('".
+ $currentEpsg["epsg"] ."',".
+ (is_null($currentEpsg["minx"]) ? "null" : $currentEpsg["minx"]) .",".
+ (is_null($currentEpsg["miny"]) ? "null" : $currentEpsg["miny"]) .",".
+ (is_null($currentEpsg["maxx"]) ? "null" : $currentEpsg["maxx"]) .",".
+ (is_null($currentEpsg["maxy"]) ? "null" : $currentEpsg["maxy"]) .");";
+ }
+ if (!is_null($currentEpsg["epsg"])) {
+ if($parent){
+ $str .= "parent.";
+ }
+ $str .= "layer_addEpsg('".
+ $currentEpsg["epsg"] ."',".
+ (is_null($currentEpsg["minx"]) ? "null" : $currentEpsg["minx"]) .",".
+ (is_null($currentEpsg["miny"]) ? "null" : $currentEpsg["miny"]) .",".
+ (is_null($currentEpsg["maxx"]) ? "null" : $currentEpsg["maxx"]) .",".
+ (is_null($currentEpsg["maxy"]) ? "null" : $currentEpsg["maxy"]) .");";
+ }
+ }
+ for($j=0; $i==0 && $j<count($this->wms_srs);$j++){
+ $found = false;
+ for ($k = 0; $k < count($this->objLayer[$i]->layer_epsg); $k++){
+ if ($this->objLayer[$i]->layer_epsg[$k]["epsg"] === $this->wms_srs[$j]) {
+ $found = true;
+ break;
+ }
+ }
+ if ($found) {
+ continue;
+ }
+
+ if($parent){
+ $str .= "parent.";
+ }
+ $str .= "wms_addSRS('".
+ $this->wms_srs[$j] ."', null, null, null, null);\n";
+ }
+ for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+ if($parent){
+ $str .= "parent.";
+ }
+ $str .= "wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"].
+ "', '".$this->objLayer[$i]->layer_style[$j]["title"].
+ "', ".$j.
+ ",".$i.
+ ",'".$this->objLayer[$i]->layer_style[$j]["legendurl"].
+ "', '".$this->objLayer[$i]->layer_style[$j]["legendurlformat"]."');";
+ }
+ }
+ return $str;
+ }
+
+ function createJsLayerObjFromWMS($parent=0, $layer_name){
+ if(!$this->wms_title || $this->wms_title == ""){
+ echo " alert('Error: no valid capabilities-document !!');";
+ die; exit;
+ }
+ if($parent){
+ echo "parent.";
+ }
+ // wms_title and abstract have previously been urlencoded
+ // this solution may not yet be the ultimate one
+ print("add_wms('".
+ $this->wms_id ."','".
+ $this->wms_version ."','".
+ preg_replace("/'/", "", $this->wms_title) ."','".
+ preg_replace("/'/", "", $this->wms_abstract) ."','".
+ $this->wms_getmap ."','" .
+ $this->wms_getfeatureinfo ."','".
+ $this->wms_getlegendurl ."','".
+ $this->wms_filter ."','".
+ $this->gui_wms_mapformat ."','".
+ $this->gui_wms_featureinfoformat ."','".
+ $this->gui_wms_exceptionformat . "','".
+ $this->gui_wms_epsg ."','".
+ $this->gui_wms_visible ."','".
+ $this->gui_wms_opacity ."','".
+ $this->gui_wms_sldurl ."');");
+
+ for($i=0;$i<count($this->data_format);$i++){
+ if($parent){
+ echo "parent.";
+ }
+ echo "wms_add_data_type_format('". $this->data_type[$i] ."','". $this->data_format[$i] ."');";
+ }
+ for($i=0; $i<count($this->objLayer); $i++){
+ if($this->objLayer[$i]->layer_name == $layer_name|| $this->objLayer[$i]->layer_pos == 0){
+
+ if($parent){
+ echo "parent.";
+ }
+ print ("wms_add_layer('".
+ $this->objLayer[$i]->layer_parent ."','".
+ $this->objLayer[$i]->layer_uid ."','".
+ $this->objLayer[$i]->layer_name . "','".
+ addslashes($this->objLayer[$i]->layer_title) ."','".
+ $this->objLayer[$i]->layer_dataurl_href ."','".
+ $this->objLayer[$i]->layer_pos ."','".
+ $this->objLayer[$i]->layer_queryable ."','".
+ $this->objLayer[$i]->layer_minscale . "','".
+ $this->objLayer[$i]->layer_maxscale ."','".
+ $this->objLayer[$i]->layer_metadataurl ."','".
+ $this->objLayer[$i]->gui_layer_wms_id ."','".
+ $this->objLayer[$i]->gui_layer_status ."','".
+ $this->objLayer[$i]->gui_layer_style ."','".
+ $this->objLayer[$i]->gui_layer_selectable ."','".
+ $this->objLayer[$i]->gui_layer_visible ."','".
+ $this->objLayer[$i]->gui_layer_queryable ."','".
+ $this->objLayer[$i]->gui_layer_querylayer ."','".
+ $this->objLayer[$i]->gui_layer_minscale ."','".
+ $this->objLayer[$i]->gui_layer_maxscale ."','".
+ $this->objLayer[$i]->gui_layer_wfs_featuretype ."');");
+ for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+ if($i==0){
+ if($parent){
+ echo "parent.";
+ }
+ print("wms_addSRS('".
+ $this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','".
+ $this->objLayer[$i]->layer_epsg[$j]["minx"] ."','".
+ $this->objLayer[$i]->layer_epsg[$j]["miny"] ."','".
+ $this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','".
+ $this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');");
+ }
+ if($parent){
+ echo "parent.";
+ }
+ print("layer_addEpsg('".
+ $this->objLayer[$i]->layer_epsg[$j]["epsg"] ."','".
+ $this->objLayer[$i]->layer_epsg[$j]["minx"] ."','".
+ $this->objLayer[$i]->layer_epsg[$j]["miny"] ."','".
+ $this->objLayer[$i]->layer_epsg[$j]["maxx"] ."','".
+ $this->objLayer[$i]->layer_epsg[$j]["maxy"] ."');");
+ }
+ for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+ if($parent){
+ echo "parent.";
+ }
+ print("wms_addLayerStyle('".$this->objLayer[$i]->layer_style[$j]["name"]."', '".$this->objLayer[$i]->layer_style[$j]["title"]."', ".$j.",".$i.",'".$this->objLayer[$i]->layer_style[$j]["legendurl"]."', '".$this->objLayer[$i]->layer_style[$j]["legendurlformat"]."');");
+ }
+ }
+ }
+ }
+
+
+ /**
+ * writeObjInDB
+ *
+ * this function exports the information from the xml to the mapbender database
+ */
+ function writeObjInDB($gui_id){
+ global $con;
+ if (func_num_args() == 2) { //new for HTTP Authentication
+ $auth = func_get_arg(1);
+ $username = $auth['username'];
+ $password = $auth['password'];
+ $authType = $auth['auth_type'];
+ }
+ else {
+ $username = '';
+ $password = '';
+ $authType = '';
+ }
+ $admin = new administration();
+
+ $this->checkObj();
+ db_begin();
+
+ # TABLE wms
+ $sql = "INSERT INTO wms (wms_version, wms_title, wms_abstract, wms_getcapabilities, wms_getmap, ";
+ $sql.= "wms_getfeatureinfo, wms_getlegendurl, wms_getcapabilities_doc, wms_upload_url, fees, ";
+ $sql .= "accessconstraints, contactperson, contactposition, contactorganization, address, city, ";
+ $sql .= "stateorprovince, postcode, country, contactvoicetelephone, contactfacsimiletelephone, contactelectronicmailaddress, ";
+ $sql .= "wms_owner,wms_timestamp,wms_username,wms_password,wms_auth_type,";
+ $sql .= "wms_supportsld, wms_userlayer, wms_userstyle, wms_remotewfs) ";
+ $sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31)";
+ $v = array(
+ $this->wms_version,
+ $this->wms_title,
+ $this->wms_abstract,
+ $this->wms_getcapabilities,
+ $this->wms_getmap,
+ $this->wms_getfeatureinfo,
+ $this->wms_getlegendurl,
+ $admin->char_encode($this->wms_getcapabilities_doc),
+ $this->wms_upload_url,
+ $this->fees,
+ $this->accessconstraints,
+ $this->contactperson,
+ $this->contactposition,
+ $this->contactorganization,
+ $this->address,
+ $this->city,
+ $this->stateorprovince,
+ $this->postcode,
+ $this->country,
+ $this->contactvoicetelephone,
+ $this->contactfacsimiletelephone,
+ $this->contactelectronicmailaddress,
+ Mapbender::session()->get('mb_user_id'),
+ strtotime("now"),
+ $username,
+ $password,
+ $authType,
+ $this->wms_supportsld,
+ $this->wms_userlayer,
+ $this->wms_userstyle,
+ $this->wms_remotewfs
+ );
+ $t = array(
+ 's','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s',
+ 's','s','s','s','s','s','i','i','s','s','s','s','s','s','s'
+ );
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ return null;
+ }
+
+ $myWMS = db_insert_id($con,'wms', 'wms_id');
+
+ if ($authType != '') { //some authentication is needed!
+ $admin = new administration();
+ echo "WMS ID: ".$myWMS;
+ $admin->setWMSOWSstring($myWMS, 1);
+ }
+
+ # TABLE layer and gui_layer
+
+ for($i=0; $i<count($this->objLayer); $i++){
+ $this->insertLayer($i,$myWMS,$gui_id);
+ $this->insertGuiLayer($i,$myWMS,$gui_id);
+ }
+
+
+ #TABLE wms_srs
+ $this->insertSRS($myWMS);
+
+ # TABLE wms_format
+ $this->insertFormat($myWMS);
+
+ # TABLE gui_wms
+
+ $sql ="SELECT MAX(gui_wms_position) AS pos FROM gui_wms WHERE fkey_gui_id = $1";
+ $v = array($gui_id);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ if (db_result($res, 0,"pos") > -1) {
+ $position = db_result($res, 0,"pos") + 1;
+ }
+ else {
+ $position = 0;
+ }
+
+ $sql ="INSERT INTO gui_wms (fkey_gui_id, fkey_wms_id, gui_wms_position, gui_wms_mapformat, ";
+ $sql .= "gui_wms_featureinfoformat, gui_wms_exceptionformat, gui_wms_epsg)";
+ $sql .= "VALUES($1,$2,$3,$4,$5,$6,$7)";
+ $v = array(
+ $gui_id,
+ $myWMS,
+ $position,
+ $this->gui_wms_mapformat,
+ $this->gui_wms_featureinfoformat,
+ $this->gui_wms_exceptionformat,
+ $this->gui_wms_epsg
+ );
+ $t = array('s','i','i','s','s','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ return null;
+ }
+ db_commit();
+
+ //
+ // update GeoRSS feed
+ //
+ $geoRssFactory = new GeoRssFactory();
+ $geoRss = $geoRssFactory->loadOrCreate(GEO_RSS_FILE);
+ if (!is_null($geoRss)) {
+ $geoRssItem = new GeoRssItem();
+ $geoRssItem->setTitle("NEW: " . $this->wms_title);
+ $geoRssItem->setDescription($this->wms_abstract);
+ $geoRssItem->setUrl(self::getWmsMetadataUrl($myWMS));
+
+ for ($j = 0; $j < count($this->objLayer[0]->layer_epsg); $j++) {
+ $currentEpsg = $this->objLayer[0]->layer_epsg[$j];
+ if ($currentEpsg["epsg"] === "EPSG:4326") {
+ $currentBbox = new Mapbender_bbox(
+ $currentEpsg["minx"],
+ $currentEpsg["miny"],
+ $currentEpsg["maxx"],
+ $currentEpsg["maxy"],
+ $currentEpsg["epsg"]
+ );
+ $geoRssItem->setBbox($currentBbox);
+ break;
+ }
+ }
+
+ $geoRss->append($geoRssItem);
+ $geoRss->saveAsFile();
+ }
+
+ #Changes JW
+ $this->wms_id = $myWMS;
+ }
+ function insertLayer($i,$myWMS){
+ global $con;
+ $sql = "INSERT INTO layer(fkey_wms_id, layer_pos, layer_parent, layer_name, layer_title, ";
+ $sql .= " layer_queryable, layer_minscale, layer_maxscale,layer_dataurl,layer_metadataurl,layer_abstract) ";
+ $sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)";
+ if($this->objLayer[$i]->layer_id != null){
+ $tmpPos = $this->objLayer[$i]->layer_id;
+ }
+ else {
+ $tmpPos .= 0;
+ }
+ if($this->objLayer[$i]->layer_parent == '' && $this->objLayer[$i]->layer_parent != '0'){
+ $this->objLayer[$i]->layer_parent = '';
+ }
+ $v = array($myWMS,$tmpPos,$this->objLayer[$i]->layer_parent,$this->objLayer[$i]->layer_name,
+ $this->objLayer[$i]->layer_title,
+ $this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
+ $this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
+ $this->objLayer[$i]->layer_metadataurl,$this->objLayer[$i]->layer_abstract);
+ $t = array('i','i','s','s','s','i','i','i','s','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ else {
+ # save the id of each layer: set param2 true
+ $this->objLayer[$i]->db_id = db_insert_id($con, 'layer','layer_id');
+ $this->insertLayerEPSG($i);
+
+ # TABLE layer_style for each layer
+ $this->insertLayerStyle($i);
+
+ # insert Keywords
+ $this->insertLayerKeyword($i);
+
+ }
+ }
+ function updateLayer($i,$myWMS){
+ $sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
+ $v = array($myWMS,$this->objLayer[$i]->layer_name);
+ $t = array('i','s');
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ $l_id = $row['layer_id'];
+ }
+ else{
+ db_rollback();
+ $e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name);
+ return;
+ }
+
+ $sql = "UPDATE layer SET ";
+ $sql .= "layer_pos = $1, ";
+ $sql .= "layer_parent = $2, ";
+ $sql .= "layer_title = $3, ";
+ $sql .= "layer_queryable = $4, ";
+ $sql .= "layer_minscale = $5, ";
+ $sql .= "layer_maxscale = $6, ";
+ $sql .= "layer_dataurl = $7, ";
+ $sql .= "layer_metadataurl = $8, ";
+ $sql .= "layer_abstract = $9 ";
+ $sql .= "WHERE layer_id = $10";
+
+ if($this->objLayer[$i]->layer_id != null){
+ $tmpPos = $this->objLayer[$i]->layer_id;
+ }
+ else {
+ $tmpPos .= 0;
+ }
+ if($this->objLayer[$i]->layer_parent == '' && $this->objLayer[$i]->layer_parent != '0'){
+ $this->objLayer[$i]->layer_parent = '';
+ }
+ $v = array($tmpPos,$this->objLayer[$i]->layer_parent,
+ $this->objLayer[$i]->layer_title,
+ $this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
+ $this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl_href,
+ $this->objLayer[$i]->layer_metadataurl,$this->objLayer[$i]->layer_abstract, $l_id
+ );
+ $t = array('i','s','s','i','i','i','s','s','s','i');
+ $res = db_prep_query($sql,$v,$t);
+ if($this->overwrite == true){
+ $sql = "UPDATE layer SET ";
+ $sql .= "layer_title = $1, ";
+ $sql .= "layer_abstract = $2 ";
+ $sql .= "WHERE layer_id = $3";
+
+ $v = array($this->objLayer[$i]->layer_title,$this->objLayer[$i]->layer_abstract, $l_id);
+ $t = array('s','s','i');
+ $res = db_prep_query($sql,$v,$t);
+ }
+ if(!$res){
+ db_rollback();
+ }
+ else {
+
+ # save the id of each layer: set param2 true
+ $this->objLayer[$i]->db_id = $l_id;
+ $this->insertLayerEPSG($i);
+
+ # TABLE layer_style for each layer
+ $this->insertLayerStyle($i);
+ if($this->overwrite == true){
+ $this->insertLayerKeyword($i);
+ }
+ }
+ }
+ function insertGuiLayer($i,$myWMS,$gui_id){
+ # table gui_layer
+
+ $sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
+ $sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
+ $sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority, gui_layer_style) ";
+ $sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)";
+ if(count($this->objLayer[$i]->layer_style)>0){
+ $layer_style_name = $this->objLayer[$i]->layer_style[0]["name"];
+ }
+ else{
+ $layer_style_name = NULL;
+ }
+ $v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,1,1,1,$this->objLayer[$i]->layer_queryable,
+ $this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i,$layer_style_name);
+ $t = array('s','i','i','i','i','i','i','i','i','i','i','s');
+ $res = db_prep_query($sql,$v,$t);
+ #$e = new mb_exception("name des insert styles und fkey_layer_id: ".$layer_style_name." --- ".$this->objLayer[$i]->db_id);
+ if(!$res){
+ db_rollback();
+ }
+ }
+ function appendGuiLayer($i,$myWMS,$gui_id){
+ # table gui_layer
+
+ $sql = "INSERT INTO gui_layer (fkey_gui_id, fkey_layer_id, gui_layer_wms_id, ";
+ $sql .= "gui_layer_status, gui_layer_selectable, gui_layer_visible, gui_layer_queryable, ";
+ $sql .= "gui_layer_querylayer,gui_layer_minscale,gui_layer_maxscale, gui_layer_priority, gui_layer_style) ";
+ $sql .= "VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)";
+ if(count($this->objLayer[$i]->layer_style)>0){
+ $layer_style_name = $this->objLayer[$i]->layer_style[0]["name"];
+ }
+ else{
+ $layer_style_name = NULL;
+ }
+ $v = array($gui_id,$this->objLayer[$i]->db_id,$myWMS,0,0,0,$this->objLayer[$i]->layer_queryable,
+ $this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,$this->objLayer[$i]->layer_maxscale,$i,$layer_style_name);
+ $t = array('s','i','i','i','i','i','i','i','i','i','i','s');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ }
+ function insertSRS($myWMS){
+ for($i=0; $i<count($this->wms_srs);$i++){
+ $sql ="INSERT INTO wms_srs (fkey_wms_id, wms_srs) values($1,$2)";
+ $v = array($myWMS,mb_strtoupper($this->wms_srs[$i]));
+ $t = array('i','s');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ }
+ }
+ function insertFormat($myWMS){
+ for($i=0; $i<count($this->data_type);$i++){
+ $sql ="INSERT INTO wms_format (fkey_wms_id, data_type, data_format) ";
+ $sql .= " VALUES($1,$2,$3)";
+ $v = array($myWMS,$this->data_type[$i],$this->data_format[$i]);
+ $t = array('i','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ }
+ }
+ function insertLayerEPSG($i){
+ $sql = "DELETE FROM layer_epsg WHERE fkey_layer_id = $1";
+ $v = array($this->objLayer[$i]->db_id);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ for($j=0; $j<count($this->objLayer[$i]->layer_epsg);$j++){
+ $sql = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
+ $sql .= "VALUES($1,$2,$3,$4,$5,$6)";
+ $v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_epsg[$j][epsg],
+ $this->objLayer[$i]->layer_epsg[$j][minx],$this->objLayer[$i]->layer_epsg[$j][miny],
+ $this->objLayer[$i]->layer_epsg[$j][maxx],$this->objLayer[$i]->layer_epsg[$j][maxy]
+ );
+ $t = array('i','s','d','d','d','d');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ }
+ }
+ function insertLayerStyle($i){
+ $sql = "DELETE FROM layer_style WHERE fkey_layer_id = $1";
+ $v = array($this->objLayer[$i]->db_id);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ for($j=0; $j<count($this->objLayer[$i]->layer_style);$j++){
+ $sql = "INSERT INTO layer_style (fkey_layer_id, name, title, legendurl, legendurlformat) ";
+ $sql .= "VALUES($1,$2,$3,$4,$5)";
+ $v = array($this->objLayer[$i]->db_id,$this->objLayer[$i]->layer_style[$j]["name"],
+ $this->objLayer[$i]->layer_style[$j]["title"],$this->objLayer[$i]->layer_style[$j]["legendurl"],
+ $this->objLayer[$i]->layer_style[$j]["legendurlformat"]
+ );
+ $t = array('i','s','s','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ }
+ }
+ function insertLayerKeyword($i){
+ global $con;
+ $sql = "DELETE FROM layer_keyword WHERE fkey_layer_id = $1";
+ $v = array($this->objLayer[$i]->db_id);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+
+// var_dump($this);
+ $k = $this->objLayer[$i]->layer_keyword;
+// var_dump($k);
+ for($j=0; $j<count($k); $j++){
+ $keyword_id = "";
+
+ while ($keyword_id == "") {
+ $sql = "SELECT keyword_id FROM keyword WHERE UPPER(keyword) = UPPER($1)";
+ $v = array($k[$j]);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $row = db_fetch_array($res);
+ //print_r($row);
+ if ($row) {
+ $keyword_id = $row["keyword_id"];
+ }
+ else {
+ $sql_insertKeyword = "INSERT INTO keyword (keyword)";
+ $sql_insertKeyword .= "VALUES ($1)";
+ $v1 = array($k[$j]);
+ $t1 = array('s');
+ $res_insertKeyword = db_prep_query($sql_insertKeyword,$v1,$t1);
+ if(!$res_insertKeyword){
+ db_rollback();
+ }
+ }
+ }
+
+ // check if layer/keyword combination already exists
+ $sql_layerKeywordExists = "SELECT * FROM layer_keyword WHERE fkey_layer_id = $1 AND fkey_keyword_id = $2";
+ $v = array($this->objLayer[$i]->db_id, $keyword_id);
+ $t = array('i', 'i');
+ $res_layerKeywordExists = db_prep_query($sql_layerKeywordExists, $v, $t);
+ $row = db_fetch_array($res_layerKeywordExists);
+ //print_r($row);
+ if (!$row) {
+ $sql1 = "INSERT INTO layer_keyword (fkey_keyword_id,fkey_layer_id)";
+ $sql1 .= "VALUES ($1,$2)";
+ $v1 = array($keyword_id,$this->objLayer[$i]->db_id);
+ $t1 = array('i','i');
+ $res1 = db_prep_query($sql1,$v1,$t1);
+ if(!$res1){
+ db_rollback();
+ }
+ }
+ }
+ }
+ function updateObjInDB($myWMS){
+ $admin = new administration();
+ db_begin();
+
+ $sql = "UPDATE wms SET ";
+ $sql .= "wms_version = $1 ,";
+ $sql .= "wms_getcapabilities = $2 ,";
+ $sql .= "wms_getmap = $3 ,";
+ $sql .= "wms_getfeatureinfo = $4 ,";
+ $sql .= "wms_getlegendurl = $5 ,";
+ $sql .= "wms_getcapabilities_doc = $6 ,";
+ $sql .= "wms_upload_url = $7, ";
+ $sql .= "wms_owner = $8, ";
+ $sql .= "wms_timestamp = $9, ";
+ $sql .= "wms_supportsld = $10, ";
+ $sql .= "wms_userlayer = $11, ";
+ $sql .= "wms_userstyle = $12, ";
+ $sql .= "wms_remotewfs = $13 ";
+ $sql .= " WHERE wms_id = $14";
+
+ $v = array($this->wms_version,$this->wms_getcapabilities,
+ $this->wms_getmap,$this->wms_getfeatureinfo,$this->wms_getlegendurl,
+ $admin->char_encode($this->wms_getcapabilities_doc),$this->wms_upload_url,Mapbender::session()->get("mb_user_id"),strtotime("now"),
+ $this->wms_supportsld,$this->wms_userlayer,$this->wms_userstyle,$this->wms_remotewfs,$myWMS);
+ $t = array('s','s','s','s','s','s','s','i','i','s','s','s','s','i');
+
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+
+ if($this->overwrite == true){
+ $sql = "UPDATE wms SET ";
+ $sql .= "wms_title = $1 ,";
+ $sql .= "wms_abstract = $2 ,";
+ $sql .= "fees = $3, ";
+ $sql .= "accessconstraints = $4, ";
+ $sql .= "contactperson = $5, ";
+ $sql .= "contactposition = $6, ";
+ $sql .= "contactorganization = $7, ";
+ $sql .= "address = $8, ";
+ $sql .= "city = $9, ";
+ $sql .= "stateorprovince = $10, ";
+ $sql .= "postcode = $11, ";
+ $sql .= "country = $12, ";
+ $sql .= "contactvoicetelephone = $13, ";
+ $sql .= "contactfacsimiletelephone = $14, ";
+ $sql .= "contactelectronicmailaddress = $15 ";
+ $sql .= " WHERE wms_id = $16";
+
+ $v = array($this->wms_title,$this->wms_abstract,$this->fees,$this->accessconstraints,
+ $this->contactperson,$this->contactposition,$this->contactorganization,$this->address,
+ $this->city,$this->stateorprovince,$this->postcode,$this->country,$this->contactvoicetelephone,
+ $this->contactfacsimiletelephone,$this->contactelectronicmailaddress,$myWMS);
+ $t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ }
+
+ # delete and refill srs and formats
+ $sql = "DELETE FROM wms_srs WHERE fkey_wms_id = $1 ";
+ $v = array($myWMS);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ $this->insertSRS($myWMS);
+
+ $sql = "DELETE FROM wms_format WHERE fkey_wms_id = $1 ";
+ $v = array($myWMS);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ $this->insertFormat($myWMS);
+
+ # update gui_wms
+ $this->update_gui_wms($myWMS);
+
+ # update TABLE layer
+ $oldLayerNameArray = array();
+ $v = array($myWMS);
+ $t = array('i');
+ $c = 2;
+ $sql = "SELECT layer_name, layer_title, layer_abstract FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
+ for($i=0; $i<count($this->objLayer); $i++){
+ if($i>0){$sql .= ',';}
+ $sql .= "$".$c;
+ array_push($v,$this->objLayer[$i]->layer_name);
+ array_push($t,'s');
+ $c++;
+ }
+ $sql .= ")";
+ $res = db_prep_query($sql,$v,$t);
+ while ($row = db_fetch_array($res)) {
+ $oldLayerNameArray[]= array(
+ "name" => $row["layer_name"],
+ "title" => $row["layer_title"],
+ "abstract" => $row["layer_abstract"]
+ );
+
+ }
+
+ # delete all layer which are outdated
+ $v = array($myWMS);
+ $t = array('i');
+ $c = 2;
+ $sql = "DELETE FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
+ for($i=0; $i<count($this->objLayer); $i++){
+ if($i>0){$sql .= ',';}
+ $sql .= "$".$c;
+ array_push($v,$this->objLayer[$i]->layer_name);
+ array_push($t,'s');
+ $c++;
+ }
+ $sql .= ")";
+
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+
+ # update or insert?
+ $sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1";
+ $v = array($myWMS);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $exLayer = array();
+ while($row = db_fetch_array($res)){
+ array_push($exLayer,$row["layer_name"]);
+ }
+
+ $sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1";
+ $v = array($myWMS);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $exGui = array();
+ while($row = db_fetch_array($res)){
+ array_push($exGui,$row["fkey_gui_id"]);
+ }
+ $newLayerArray = array();
+ for($i=0; $i<count($this->objLayer); $i++){
+ if(in_array($this->objLayer[$i]->layer_name,$exLayer)){
+ //echo "<br>update: ".$this->objLayer[$i]->layer_name;
+ $this->updateLayer($i,$myWMS);
+ for($j=0; $j<count($exGui); $j++){
+ $this->updateGuiLayer($i,$myWMS,$exGui[$j]);
+ }
+ }
+ else{
+ //echo "<br>append: ".$this->objLayer[$i]->layer_name;
+ $this->insertLayer($i,$myWMS);
+ $newLayerArray[]= $i;
+ for($j=0; $j<count($exGui); $j++){
+ $this->appendGuiLayer($i,$myWMS,$exGui[$j]);
+ }
+ }
+ }
+ db_commit();
+ //
+ // update GeoRSS feed
+ //
+ $geoRssFactory = new GeoRssFactory();
+ $geoRss = $geoRssFactory->loadOrCreate(GEO_RSS_FILE);
+
+ if (!is_null($geoRss)) {
+
+ $geoRssItem = new GeoRssItem();
+ $geoRssItem->setTitle("UPDATED WMS: " . $this->wms_title);
+ $geoRssItem->setDescription($this->wms_abstract);
+ $geoRssItem->setUrl(self::getWmsMetadataUrl($myWMS));
+ for ($j = 0; $j < count($this->objLayer[0]->layer_epsg); $j++) {
+ $currentEpsg = $this->objLayer[0]->layer_epsg[$j];
+ if ($currentEpsg["epsg"] === "EPSG:4326") {
+ $currentBbox = new Mapbender_bbox(
+ $currentEpsg["minx"],
+ $currentEpsg["miny"],
+ $currentEpsg["maxx"],
+ $currentEpsg["maxy"],
+ $currentEpsg["epsg"]
+ );
+ $geoRssItem->setBbox($currentBbox);
+ break;
+ }
+ }
+ $geoRss->append($geoRssItem);
+
+ foreach ($newLayerArray as $newLayer) {
+ $currentLayer = $this->objLayer[$newLayer];
+ $geoRssItem = new GeoRssItem();
+ $geoRssItem->setTitle("ADDED LAYER: " . $currentLayer->layer_title);
+ $geoRssItem->setDescription($currentLayer->layer_abstract);
+ $geoRssItem->setUrl(layer::getLayerMetadataUrl($currentLayer->layer_id));
+
+ for ($j = 0; $j < count($currentLayer->layer_epsg); $j++) {
+ $currentEpsg = $currentLayer->layer_epsg[$j];
+ if ($currentEpsg["epsg"] === "EPSG:4326") {
+ $currentBbox = new Mapbender_bbox(
+ $currentEpsg["minx"],
+ $currentEpsg["miny"],
+ $currentEpsg["maxx"],
+ $currentEpsg["maxy"],
+ $currentEpsg["epsg"]
+ );
+ $geoRssItem->setBbox($currentBbox);
+ break;
+ }
+ }
+ $geoRss->append($geoRssItem);
+ }
+ foreach ($oldLayerNameArray as $oldLayer) {
+ $geoRssItem = new GeoRssItem();
+ $geoRssItem->setTitle("DELETED LAYER: " . $oldLayer["title"]);
+ $geoRssItem->setDescription($oldLayer["abstract"]);
+// $geoRssItem->setUrl();
+ $geoRss->append($geoRssItem);
+ }
+ $geoRss->saveAsFile();
+ }
+ return;
+ }
+
+ function updateGuiLayer($i,$myWMS,$gui_id){
+ $sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
+ $v = array($myWMS,$this->objLayer[$i]->layer_name);
+ $t = array('i','s');
+ $res = db_prep_query($sql,$v,$t);
+ if($row = db_fetch_array($res)){
+ $l_id = $row['layer_id'];
+ }
+ else{
+ db_rollback();
+ $e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name. " in gui: ".$gui_id);
+ return;
+ }
+
+ $sql = "SELECT * FROM gui_layer WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+ $v = array($l_id,$gui_id);
+ $t = array('i','s');
+ $res = db_prep_query($sql,$v,$t);
+ while($row = db_fetch_array($res)){
+ if($this->objLayer[$i]->layer_queryable == 0){
+ $sql1 = "UPDATE gui_layer set gui_layer_queryable = 0, gui_layer_querylayer = 0 ";
+ $sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+ $v = array($l_id,$gui_id);
+ $t = array('i','s');
+ $res1 = db_prep_query($sql1,$v,$t);
+ if(!$res1){
+
+ db_rollback();
+ }
+ }
+ if($this->objLayer[$i]->layer_queryable == 1){
+ $sql1 = "UPDATE gui_layer set gui_layer_queryable = 1 ";
+ $sql1 .= "WHERE fkey_layer_id = $1 and fkey_gui_id = $2";
+ $v = array($l_id,$gui_id);
+ $t = array('i','s');
+ $res1 = db_prep_query($sql1,$v,$t);
+ if(!$res1){
+
+ db_rollback();
+ }
+ }
+ if($row["gui_layer_minscale"] < $this->objLayer[$i]->layer_minscale){
+ $sql1 = "UPDATE gui_layer set gui_layer_minscale = $1 ";
+ $sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
+ $v = array($this->objLayer[$i]->layer_minscale,$l_id,$gui_id);
+ $t = array('i','i','s');
+ $res1 = db_prep_query($sql1,$v,$t);
+ if(!$res1){db_rollback();
+ }
+ }
+ if($row["gui_layer_maxscale"] > $this->objLayer[$i]->layer_maxscale){
+ $sql1 = "UPDATE gui_layer set gui_layer_maxscale = $1 ";
+ $sql1 .= "WHERE fkey_layer_id = $2 and fkey_gui_id = $3";
+ $v = array($this->objLayer[$i]->layer_maxscale,$l_id,$gui_id);
+ $t = array('i','i','s');
+ $res1 = db_prep_query($sql1,$v,$t);
+ if(!$res1){db_rollback();
+ }
+ }
+ }
+ }
+ function update_gui_wms($myWMS){
+ $mySubmit = null;
+ $sql = "SELECT * FROM gui_wms where fkey_wms_id = $1";
+ $v = array($myWMS);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $cnt = 0;
+ while($row = db_fetch_array($res)){
+ unset($mySubmit);
+ $myGUI[$cnt] = $row["fkey_gui_id"];
+
+ $sql = "UPDATE gui_wms SET ";
+ $v = array();
+ $t = array();
+ $paramCount = 0;
+
+ for($i=0; $i<count($this->data_type); $i++){
+ # gui_wms_mapformat
+ if(mb_strtolower($this->data_type[$i]) == "map" && mb_strtolower($this->data_format[$i]) == mb_strtolower($row["gui_wms_mapformat"])){
+ $myMapFormat = true;
+ }
+ # gui_wms_featureinfoformat
+ if(mb_strtolower($this->data_type[$i]) == "featureinfo" && mb_strtolower($this->data_format[$i]) == mb_strtolower($row["gui_wms_featureinfoformat"])){
+ $myFeatureInfoFormat = true;
+ }
+ # gui_wms_exceptionformat
+ if(mb_strtolower($this->data_type[$i]) == "exception" && mb_strtolower($this->data_format[$i]) == mb_strtolower($row["gui_wms_exceptionformat"])){
+ $myExceptionFormat = true;
+ }
+ }
+ if(!$myMapFormat){
+ $paramCount++;
+ $sql .= "gui_wms_mapformat = $" . $paramCount . " ";
+ $mySubmit = true;
+ array_push($v, $this->gui_wms_mapformat);
+ array_push($t, "s");
+ }
+ if(!$myFeatureInfoFormat){
+ if($mySubmit){ $sql .= ",";}
+ $paramCount++;
+ $sql .= "gui_wms_featureinfoformat = $" . $paramCount . " ";
+ array_push($v, $this->gui_wms_featureinfoformat);
+ array_push($t, "s");
+ $mySubmit = true;
+ }
+ if(!$myExceptionFormat){
+ if($mySubmit){ $sql .= ",";}
+ $paramCount++;
+ $sql .= "gui_wms_exceptionformat = $" . $paramCount ." ";
+ array_push($v, $this->gui_wms_exceptionformat);
+ array_push($t, "s");
+ $mySubmit = true;
+ }
+
+ # gui_wms_epsg
+ for($j=0; $j<count($this->objLayer[0]->layer_epsg);$j++){
+ if($this->objLayer[0]->layer_epsg[$j][epsg] == mb_strtoupper($row["gui_wms_epsg"])){
+ $myGUI_EPSG = true;
+ }
+ }
+ if(!$myGUI_EPSG){
+ if($mySubmit){ $sql .= ",";}
+ $paramCount++;
+ $sql .= "gui_wms_epsg = $" . $paramCount . " ";
+ array_push($v, $this->gui_wms_epsg);
+ array_push($t, "s");
+ $mySubmit = true;
+ }
+ $paramCount++;
+ $sql .= " WHERE fkey_gui_id = $" . $paramCount . " ";
+ array_push($v, $row["fkey_gui_id"]);
+ array_push($t, "s");
+
+ $paramCount++;
+ $sql .= "AND fkey_wms_id = $" . $paramCount;
+ array_push($v, $myWMS);
+ array_push($t, "i");
+ if($mySubmit){
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ echo "<pre>".$sql."</pre><br> <br><p>";
+ echo db_error();
+ echo "<br /> UPDATE ERROR -> KILL PROCESS AND ROLLBACK....................no update<br><br>";
+ $e = new mb_exception("class_wms.php: transaction: Transaction aborted, rollback.");
+ }
+ }
+ $cnt++;
+ }
+ }
+ function getVersion() {
+ return $this->wms_version;
+ }
+
+ function getCapabilities() {
+ return $this->wms_getcapabilities;
+ }
+
+ function getCapabilitiesDoc() {
+ return $this->wms_getcapabilities_doc;
+ }
+
+ /**
+ * creatObjfromDB
+ *
+ */
+ function createObjFromDB($gui_id,$wms_id){
+
+ $sql = "Select * from gui_wms where fkey_wms_id = $1 AND fkey_gui_id = $2";
+ $v = array($wms_id,$gui_id);
+ $t = array('i','s');
+ $res = db_prep_query($sql,$v,$t);
+
+ $count=0;
+ #$res_count=db_num_rows($res);
+
+
+ while($row = db_fetch_array($res)){
+ $this->gui_wms_mapformat=$row["gui_wms_mapformat"];
+ $this->gui_wms_featureinfoformat=$row["gui_wms_featureinfoformat"];
+ $this->gui_wms_exceptionformat=$row["gui_wms_exceptionformat"];
+ $this->gui_wms_epsg=$row["gui_wms_epsg"];
+ $this->gui_wms_visible = $row["gui_wms_visible"];
+ $this->gui_wms_opacity = $row["gui_wms_opacity"];
+ $this->gui_wms_sldurl = $row["gui_wms_sldurl"];
+
+ $sql = "Select * from wms where wms_id = $1 ";
+ $v = array($wms_id);
+ $t = array('i');
+ $res_wms = db_prep_query($sql,$v,$t);
+ $count_wms=0;
+ while($row2 = db_fetch_array($res_wms)){
+ $this->wms_id = $row2["wms_id"];
+ $this->wms_version = $row2["wms_version"];
+ $this->wms_title = administration::convertIncomingString($this->stripEndlineAndCarriageReturn($row2["wms_title"]));
+ $this->wms_abstract = administration::convertIncomingString($this->stripEndlineAndCarriageReturn($row2["wms_abstract"]));
+ $wmsowsproxy = $row2["wms_owsproxy"];
+ #$wmsowsproxy = "test";
+ if($wmsowsproxy != ""){
+ $owsproxyurl = OWSPROXY."/".session_id()."/".$wmsowsproxy."?";
+ $this->wms_getmap = $owsproxyurl;
+ $this->wms_getcapabilities = $owsproxyurl;
+ $this->wms_getfeatureinfo = $owsproxyurl;
+ $this->wms_getlegendurl = $owsproxyurl;
+ }
+ else{
+ $this->wms_getmap = $row2["wms_getmap"];
+ $this->wms_getcapabilities = $row2["wms_getcapabilities"];
+ $this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
+ $this->wms_getlegendurl = $row2["wms_getlegendurl"];
+ }
+ // TO DO: Capabilities document needs to
+ // be encoded to the original encoding
+ // if different from the database encoding
+ $this->wms_getcapabilities_doc = $row2["wms_getcapabilities_doc"];
+ $this->wms_filter = $row2["wms_filter"];
+ $this->wms_supportsld = $row2["wms_supportsld"];
+ $this->wms_userlayer = $row2["wms_userlayer"];
+ $this->wms_userstyle = $row2["wms_userstyle"];
+ $this->wms_remotewfs = $row2["wms_remotewfs"];
+
+ $count_wms++;
+ }
+
+ ### srs
+ $srs_sql = "SELECT * FROM wms_srs WHERE fkey_wms_id = $1 ";
+ $srs_v = array($wms_id);
+ $srs_t = array('i');
+ $srs_res = db_prep_query($srs_sql, $srs_v, $srs_t);
+ $this->wms_srs = array();
+ while($srs_row = db_fetch_array($srs_res)) {
+ $this->wms_srs[]= $srs_row["wms_srs"];
+ }
+
+ ### formats
+ $sql = "SELECT * FROM wms_format WHERE fkey_wms_id = $1 ";
+ $v = array($wms_id);
+ $t = array('i');
+ $res_wms = db_prep_query($sql,$v,$t);
+ $count_format=0;
+ while($row3 = db_fetch_array($res_wms)){
+ $this->data_type[$count_format] = $row3["data_type"];
+ $this->data_format[$count_format] = $row3["data_format"];
+ $count_format++;
+ }
+ $count++;
+ }
+
+ #layer
+ $sql = "Select * from gui_layer where gui_layer_wms_id = $1 AND fkey_gui_id = $2 ";
+ $sql .= " AND gui_layer_status = 1 ORDER BY gui_layer_priority;";
+ $v = array($wms_id,$gui_id);
+ $t = array('i','s');
+ $res = db_prep_query($sql,$v,$t);
+ $count=0;
+
+ while($row = db_fetch_array($res)){
+ $layer_id = $row["fkey_layer_id"];
+ $sql = "Select * from layer where layer_id = $1";
+ $v = array($layer_id);
+ $t = array('i');
+ $res_layer = db_prep_query($sql,$v,$t);
+ $count_layer=0;
+ while($row2 = db_fetch_array($res_layer)){
+ $this->addLayer($row2["layer_pos"],$row2["layer_parent"]);
+ $layer_cnt=count($this->objLayer)-1;
+ $this->objLayer[$layer_cnt]->layer_uid = $layer_id;
+ $this->objLayer[$layer_cnt]->layer_name = administration::convertIncomingString($row2["layer_name"]);
+ $this->objLayer[$layer_cnt]->layer_title = administration::convertIncomingString($row2["layer_title"]);
+ $this->objLayer[$layer_cnt]->layer_dataurl_href =$row2["layer_dataurl"];
+ $this->objLayer[$layer_cnt]->layer_metadataurl =$row2["layer_metadataurl"];
+ $this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];
+ $this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_pos"];
+ $this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_queryable"];
+ $this->objLayer[$layer_cnt]->layer_minscale =$row2["layer_minscale"];
+ $this->objLayer[$layer_cnt]->layer_maxscale = $row2["layer_maxscale"];
+ $count_layer++;
+ }
+ $this->objLayer[$layer_cnt]->layer_uid = $layer_id;
+ $this->objLayer[$layer_cnt]->gui_layer_wms_id = $row["gui_layer_wms_id"];
+ $this->objLayer[$layer_cnt]->gui_layer_selectable = $row["gui_layer_selectable"];
+ $this->objLayer[$layer_cnt]->gui_layer_visible = $row["gui_layer_visible"];
+ $this->objLayer[$layer_cnt]->gui_layer_queryable = $row["gui_layer_queryable"];
+ $this->objLayer[$layer_cnt]->gui_layer_querylayer = $row["gui_layer_querylayer"];
+ $this->objLayer[$layer_cnt]->gui_layer_minscale = $row["gui_layer_minscale"];
+ $this->objLayer[$layer_cnt]->gui_layer_maxscale = $row["gui_layer_maxscale"];
+ $this->objLayer[$layer_cnt]->gui_layer_style = $row["gui_layer_style"];
+ $this->objLayer[$layer_cnt]->gui_layer_wfs_featuretype = $row["gui_layer_wfs_featuretype"];
+
+ $sql = "Select * from layer_epsg where fkey_layer_id = $1 ORDER BY fkey_layer_id";
+ $v = array($layer_id);
+ $t = array('i');
+ $res_layer_epsg = db_prep_query($sql,$v,$t);
+
+ $count_layer_epsg=0;
+ while($row2 = db_fetch_array($res_layer_epsg)){
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["epsg"]=$row2["epsg"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["minx"]=$row2["minx"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["miny"]=$row2["miny"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxx"]=$row2["maxx"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxy"]=$row2["maxy"];
+ $count_layer_epsg++;
+ }
+
+ ### handle styles
+ $sql = "SELECT * FROM layer_style WHERE fkey_layer_id = $1 ";
+ $v = array($layer_id);
+ $t = array('i');
+ $res_style = db_prep_query($sql,$v,$t);
+ $count_layer_style = 0;
+ while($row2 = db_fetch_array($res_style)){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["name"] = $row2["name"] ? $row2["name"] : "default";
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["title"]=$row2["title"];
+ if($wmsowsproxy != ""){
+ if($row2["legendurl"]!=''){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$owsproxyurl.
+ "REQUEST=getlegendgraphic&VERSION=".$this->wms_version."&LAYER=".$this->objLayer[$layer_cnt]->layer_name."&FORMAT=".$row2["legendurlformat"].
+ "&STYLE=".$row2["name"];
+ }
+ }
+ else{
+ if($row2["legendurl"]!=''){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$row2["legendurl"];
+ #$e = new mb_exception("legendurl = ".$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]);
+ }
+ }
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurlformat"]=$row2["legendurlformat"];
+ $count_layer_style++;
+ }
+ $count++;
+ }
+ }
+ /** end createObjfromDB **/
+
+ /**
+ * creatObjfromDBNoGui
+ *
+ */
+ function createObjFromDBNoGui($wms_id){
+
+ $sql = "Select * from wms where wms_id = $1 ";
+ $v = array($wms_id);
+ $t = array('i');
+ $res_wms = db_prep_query($sql,$v,$t);
+ $count_wms=0;
+ while($row2 = db_fetch_array($res_wms)){
+ $this->wms_id = $row2["wms_id"];
+ $this->wms_version = $row2["wms_version"];
+ $this->wms_title = $this->stripEndlineAndCarriageReturn($row2["wms_title"]);
+ $this->wms_abstract = $this->stripEndlineAndCarriageReturn($row2["wms_abstract"]);
+ $wmsowsproxy = $row2["wms_owsproxy"];
+ #$wmsowsproxy = "test";
+ if($wmsowsproxy != ""){
+ $owsproxyurl = OWSPROXY."/".session_id()."/".$wmsowsproxy."?";
+ $this->wms_getmap = $owsproxyurl;
+ $this->wms_getcapabilities = $owsproxyurl;
+ $this->wms_getfeatureinfo = $owsproxyurl;
+ $this->wms_getlegendurl = $owsproxyurl;
+ }
+ else{
+ $this->wms_getmap = $row2["wms_getmap"];
+ $this->wms_getcapabilities = $row2["wms_getcapabilities"];
+ $this->wms_getfeatureinfo = $row2["wms_getfeatureinfo"];
+ $this->wms_getlegendurl = $row2["wms_getlegendurl"];
+ }
+ // TO DO: Capabilities document needs to
+ // be encoded to the original encoding
+ // if different from the database encoding
+ $this->wms_getcapabilities_doc = $row2["wms_getcapabilities_doc"];
+ $this->wms_filter = $row2["wms_filter"];
+ $this->wms_supportsld = $row2["wms_supportsld"];
+ $this->wms_userlayer = $row2["wms_userlayer"];
+ $this->wms_userstyle = $row2["wms_userstyle"];
+ $this->wms_remotewfs = $row2["wms_remotewfs"];
+
+ #some default
+ $this->gui_wms_visible = 1;
+ $this->gui_wms_opacity = 100;
+ $this->gui_wms_epsg=$row["gui_wms_epsg"];
+ $this->gui_wms_sldurl = $row["gui_wms_sldurl"];
+
+ if($this->wms_version == "1.0.0"){
+ $this->gui_wms_mapformat = "PNG";
+ $this->gui_wms_featureinfoformat = "MIME";
+ $this->gui_wms_exceptionformat = "INIMAGE";
+ }
+ /*define defaults for wms-version 1.1.0 and 1.1.1*/
+ else{
+ $this->gui_wms_mapformat = "image/png";
+ $this->gui_wms_featureinfoformat = "text/html";
+ $this->gui_wms_exceptionformat = "application/vnd.ogc.se_inimage";
+ }
+
+ $count_wms++;
+ }
+
+ ### formats
+ $sql = "SELECT * FROM wms_format WHERE fkey_wms_id = $1 ";
+ $v = array($wms_id);
+ $t = array('i');
+ $res_wms = db_prep_query($sql,$v,$t);
+ $count_format=0;
+ while($row3 = db_fetch_array($res_wms)){
+ $this->data_type[$count_format] = $row3["data_type"];
+ $this->data_format[$count_format] = $row3["data_format"];
+ $count_format++;
+ }
+
+
+ $sql = "Select * from layer where fkey_wms_id = $1";
+ $v = array($wms_id);
+ $t = array('i');
+ $res_layer = db_prep_query($sql,$v,$t);
+ $count_layer=0;
+ while($row2 = db_fetch_array($res_layer)){
+ $this->addLayer($row2["layer_pos"],$row2["layer_parent"]);
+ $layer_cnt=count($this->objLayer)-1;
+ $this->objLayer[$layer_cnt]->layer_uid = $row2["layer_id"];
+ $this->objLayer[$layer_cnt]->layer_name =$row2["layer_name"];
+ $this->objLayer[$layer_cnt]->layer_title =$row2["layer_title"];
+ $this->objLayer[$layer_cnt]->layer_dataurl_href =$row2["layer_dataurl"];
+ $this->objLayer[$layer_cnt]->layer_metadataurl =$row2["layer_metadataurl"];
+ $this->objLayer[$layer_cnt]->layer_pos =$row2["layer_pos"];
+ $this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_pos"];
+ $this->objLayer[$layer_cnt]->layer_queryable =$row2["layer_queryable"];
+ $this->objLayer[$layer_cnt]->layer_minscale =$row2["layer_minscale"];
+ $this->objLayer[$layer_cnt]->layer_maxscale = $row2["layer_maxscale"];
+
+ if($this->objLayer[$layer_cnt]->layer_minscale == ""){
+ $this->objLayer[$layer_cnt]->layer_minscale = 0;
+ }
+ if($this->objLayer[$layer_cnt]->layer_maxscale == ""){
+ $this->objLayer[$layer_cnt]->layer_maxscale = 0;
+ }
+ $this->objLayer[$layer_cnt]->gui_layer_minscale = $this->objLayer[$layer_cnt]->layer_minscale;
+ $this->objLayer[$layer_cnt]->gui_layer_maxscale = $this->objLayer[$layer_cnt]->layer_maxscale;
+
+ $sql = "Select * from layer_epsg where fkey_layer_id = $1 ORDER BY fkey_layer_id";
+ $v = array($this->objLayer[$layer_cnt]->layer_uid);
+ $t = array('i');
+ $res_layer_epsg = db_prep_query($sql,$v,$t);
+
+ $count_layer_epsg=0;
+ while($row2 = db_fetch_array($res_layer_epsg)){
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["epsg"]=$row2["epsg"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["minx"]=$row2["minx"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["miny"]=$row2["miny"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxx"]=$row2["maxx"];
+ $this->objLayer[$layer_cnt]->layer_epsg[$count_layer_epsg]["maxy"]=$row2["maxy"];
+ $count_layer_epsg++;
+ }
+
+ ### handle styles
+ $sql = "SELECT * FROM layer_style WHERE fkey_layer_id = $1 ";
+ $v = array($this->objLayer[$layer_cnt]->layer_uid);
+ $t = array('i');
+ $res_style = db_prep_query($sql,$v,$t);
+ $count_layer_style = 0;
+ while($row2 = db_fetch_array($res_style)){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["name"]=$row2["name"];
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["title"]=$row2["title"];
+ if($wmsowsproxy != ""){
+ if($row2["legendurl"]!=''){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$owsproxyurl.
+ "REQUEST=getlegendgraphic&VERSION=".$this->wms_version."&LAYER=".$this->objLayer[$layer_cnt]->layer_name."&FORMAT=".$row2["legendurlformat"].
+ "&STYLE=".$row2["name"];
+ }
+ }
+ else{
+ if($row2["legendurl"]!=''){
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]=$row2["legendurl"];
+ #$e = new mb_exception("legendurl = ".$this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurl"]);
+ }
+ }
+ $this->objLayer[$layer_cnt]->layer_style[$count_layer_style]["legendurlformat"]=$row2["legendurlformat"];
+ $count_layer_style++;
+ }
+
+ $count_layer++;
+ }
+
+ }
+ /** end createObjfromDBNoGui **/
+
+ /**
+ * function checkObjExistsInDB()
+ *
+ * this function checks wether the onlineresource already exists in the database.
+ */
+ function checkObjExistsInDB(){
+
+ $sql = "Select * from wms where wms_getcapabilities = $1";
+ $v = array($this->wms_getcapabilities);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $res_count= db_num_rows($res);
+ $wms_id=0;
+ if($res_count>0){
+ $count=0;
+ while($row = db_fetch_array($res)){
+ $wms_id=$row["wms_id"];
+ $count++;
+ }
+ }
+ return $wms_id;
+ }
+
+ function displayDBInformation(){
+ echo $this->wms_getcapabilities;
+ $sql="Select * from wms where wms_getcapabilities = $1";
+ $v = array($this->wms_getcapabilities);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $count=0;
+ while($row = db_fetch_array($res)){
+ echo "count: ".$count."<br>";
+ $wms_id=$row["wms_id"];
+ echo "version: " .$wms_id." <br>";
+ echo "title: " .$row["wms_version"]. " <br>";
+ echo "abstract: " . $row["wms_title"] . " <br>";
+ echo "maprequest: " .$row["wms_abstract"] . " <br>";
+ echo "capabilitiesrequest: " . $row["wms_getcapabilities"] . " <br>";
+ echo "featureinforequest: " . $row["wms_getmap"]. " <br>";
+ echo "gui_wms_mapformat: " . $row["wms_getfeatureinfo"] . " <br>---------<br>";
+ $count++;
+ }
+ echo "----<br> wms_id: ".$wms_id."<br>";
+
+ $sql = "Select * from gui_wms where fkey_wms_id = $1";
+ $v = array($wms_id);
+ $t = array('i');
+ echo "sql: ".$sql." <br>---------<br>";
+ $res = db_prep_query($sql,$v,$t);
+ $res_count= db_num_rows($res);
+ echo "result count: ".$res_count." <br>---------<br>";
+
+ $count=0;
+ while($row = db_fetch_array($res)){
+ echo "gui_wms_featureinfoformat: " . $row["gui_wms_featureinfoformat"]." <br>";
+ echo "gui_wms_exceptionformat: " . $row["gui_wms_exceptionformat"]. " <br>";
+ echo "gui_wms_epsg: " . $row["gui_wms_epsg"]. " <br>";
+ $count++;
+ }
+
+ #db_close($connect);
+ }
+
+ function checkObj(){
+ if($this->wms_getcapabilities == '' || $this->wms_getmap == '' ){
+ echo "<br>Missing parameters: <br>";
+ $this->displayWMS();
+ print_r($this);
+ echo "<br> Data not committed<br>";
+ die();
+ }
+ }
+
+ public static function getWmsIdByLayerId ($id) {
+ $sql = "SELECT DISTINCT fkey_wms_id FROM layer WHERE layer_id = $1";
+ $res = db_prep_query($sql, array($id), array("i"));
+ $row = db_fetch_assoc($res);
+ if ($row) {
+ return $row["fkey_wms_id"];
+ }
+ return null;
+ }
+
+ /**
+ * Selects all WMS of the current user from the database.
+ * Then it creates the corresponding WMS object and returns
+ * these objects as an array.
+ *
+ * @return wms[]
+ * @param $appId String
+ */
+ public static function selectMyWmsByApplication ($appId) {
+ // check if user is permitted to access the application
+ $currentUser = new User(Mapbender::session()->get("mb_user_id"));
+ $appArray = $currentUser->getApplicationsByPermission(false);
+ if (!in_array($appId, $appArray)) {
+ $e = new mb_warning("class_wms.php: selectMyWmsByApplication(): User '" . $currentUser . "' is not allowed to acces application '" . $appId . "'.");
+ return array();
+ }
+
+ // get WMS of this application
+ $sql = "SELECT fkey_wms_id FROM gui_wms WHERE " .
+ "fkey_gui_id = $1 ORDER BY gui_wms_position";
+ $v = array($appId);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+
+ // instantiate PHP objects and store in array
+ $wmsArray = array();
+ while ($row = db_fetch_array($res)) {
+ $currentWms = new wms();
+ $currentWms->createObjFromDB($appId, $row["fkey_wms_id"]);
+ array_push($wmsArray, $currentWms);
+ }
+ return $wmsArray;
+ }
+}
+class layer extends wms {
+ var $layer_id;
+ var $layer_parent;
+ var $layer_name;
+ var $layer_title;
+ var $layer_abstract;
+ var $layer_pos;
+ var $layer_queryable;
+ var $layer_minscale;
+ var $layer_maxscale;
+ var $layer_dataurl_href;
+ var $layer_metadataurl;
+ var $layer_keyword = array();
+ var $layer_epsg = array();
+ var $layer_style = array();
+
+ var $gui_layer_wms_id;
+ var $gui_layer_status = 1;
+ var $gui_layer_selectable = 1;
+ var $gui_layer_visible = 0;
+ var $gui_layer_queryable = 0;
+ var $gui_layer_querylayer = 0;
+ var $gui_layer_style = NULL;
+
+ function layer($id,$parent){
+ $this->layer_id = $id;
+ $this->layer_parent = $parent;
+ //var_dump($this);
+ }
+
+ public static function getLayerMetadataUrl ($layerId) {
+ return preg_replace(
+ "/(.*)frames\/login.php/",
+ "$1php/mod_layerMetadata.php?id=",
+ LOGIN
+ ) . $layerId;
+ }
+
+ public function __toString () {
+ $e = new mb_exception("TITLE: " . $this->layer_title);
+ return $this->layer_title;
+ }
+
+}
+?>
Added: branches/3_dev/core/lib/class_bbox.php
===================================================================
--- branches/3_dev/core/lib/class_bbox.php (rev 0)
+++ branches/3_dev/core/lib/class_bbox.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,171 @@
+<?php
+# $Id: class_bbox.php 3402 2009-01-05 10:30:08Z christoph $
+# http://www.mapbender.org/index.php/
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_point.php");
+
+/**
+ * A bounding box consisting of an lower left and an upper right point, and an EPSG.
+ */
+class Mapbender_bbox {
+ var $min;
+ var $max;
+ var $epsg;
+
+ /**
+ * @constructor
+ */
+ function __construct() {
+ if (func_num_args() == 5) {
+ $param0 = func_get_arg(0);
+ $param1 = func_get_arg(1);
+ $param2 = func_get_arg(2);
+ $param3 = func_get_arg(3);
+ $param4 = func_get_arg(4);
+ }
+ else if (func_num_args() == 3) {
+ $param0 = func_get_arg(0);
+ $param1 = func_get_arg(1);
+ $param2 = func_get_arg(2);
+ }
+ else {
+ return;
+ }
+
+ // params are point, point, epsg
+ if (is_a($param0, "Mapbender_point") && is_a($param1, "Mapbender_point") && !$param3 && !$param4) {
+ $e = new mb_notice("Mapbender_bbox: constructor: point1, point2, epsg");
+ $min = $param0; // is a Mapbender_point
+ $max = $param1; // is a Mapbender_point
+ $epsg = $param2; // is an EPSG code like "EPSG:4326"
+
+ if ($min->isWestOf($max) && $min->isSouthOf($max)) {
+ if ($min->epsg == $max->epsg && $min->epsg == $epsg) {
+ $this->min = $min;
+ $this->max = $max;
+ $this->epsg = $epsg;
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: EPSG mismatch!");
+ }
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: min (".$this->min.") is not southwest of max (".$this->max.")!");
+ }
+ }
+ // params are x1, y1, x2, xy, epsg
+ else {
+ $e = new mb_notice("Mapbender_bbox: constructor: x1, y1, x2, y2, epsg");
+ $min = new Mapbender_point($param0, $param1, $param4);
+ $max = new Mapbender_point($param2, $param3, $param4);
+ $epsg = $param4; // is an EPSG code like "EPSG:4326"
+
+ if ($min->isWestOf($max) && $min->isSouthOf($max)) {
+ if ($min->epsg == $max->epsg && $min->epsg == $epsg) {
+ $this->min = $min;
+ $this->max = $max;
+ $this->epsg = $epsg;
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: EPSG mismatch!");
+ }
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: constructor: min (".$this->min.") is not southwest of max (".$this->max.")!");
+ }
+
+ }
+ }
+
+ /**
+ * Computes a new bounding box, bbox1 UNION bbox2
+ */
+ static function union ($bboxArray) {
+ if (count($bboxArray) == 1) {
+ return array_pop($bboxArray);
+ }
+ elseif (count($bboxArray) >= 2) {
+
+ $bbox1 = array_pop($bboxArray);
+ $bbox2 = Mapbender_bbox::union($bboxArray);
+
+ if (!($bbox1 != null && $bbox1->isValid()) && !($bbox2 != null && $bbox2->isValid())) {
+ $e = new mb_exception("Mapbender_bbox: union: both parameters invalid!");
+ return null;
+ }
+ elseif (!($bbox1 != null && $bbox1->isValid()) && ($bbox2 != null && $bbox2->isValid())) {
+ $e = new mb_exception("Mapbender_bbox: union: first parameter invalid!");
+ return $bbox2;
+ }
+ elseif (($bbox1 != null && $bbox1->isValid()) && !($bbox2 != null && $bbox2->isValid())) {
+ $e = new mb_exception("Mapbender_bbox: union: second parameter invalid!");
+ return $bbox1;
+ }
+ else {
+ if ($bbox1->epsg == $bbox2->epsg) {
+ $e = new mb_notice("Mapbender_bbox: union: bbox1 is: " . $bbox1);
+ $e = new mb_notice("Mapbender_bbox: union: bbox2 is: " . $bbox2);
+ $e = new mb_notice("Mapbender_bbox: union: merging bbox1 and bbox2...");
+ return new Mapbender_bbox(Mapbender_point::min($bbox1->min, $bbox2->min), Mapbender_point::max($bbox1->max, $bbox2->max), $bbox1->epsg);
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: cannot process union with different EPSG codes");
+ }
+ }
+ }
+ else {
+ $e = new mb_exception("Mapbender_bbox: Invalid parameter (Not an array)!");
+ }
+ return null;
+ }
+
+ /**
+ * transforms this bbox in another EPSG
+ * @param toEpsg transform the bbox to this EPSG code, example: "EPSG:4326"
+ */
+ function transform($toEpsg) {
+ if ($this->isValid()) {
+ $this->epsg = $toEpsg;
+ $this->min->transform($toEpsg);
+ $this->max->transform($toEpsg);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * checks if lower left and upper right coordinate are set, as well as EPSG
+ */
+ function isValid() {
+ if ($this->min != null && $this->max != null && $this->epsg != null) {
+ return true;
+ }
+ $e = new mb_exception("Mapbender_bbox: this is not a valid bbox!");
+ return false;
+ }
+
+ function toHtml () {
+ return (string) $this->min->toHtml() . " | " . $this->max->toHtml();
+ }
+
+ function __toString() {
+ return (string) "[" . $this->min . $this->max . " " . $this->epsg . "]";
+ }
+}
+?>
Added: branches/3_dev/core/lib/class_georss.php
===================================================================
--- branches/3_dev/core/lib/class_georss.php (rev 0)
+++ branches/3_dev/core/lib/class_georss.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,26 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_rss.php");
+require_once(dirname(__FILE__)."/class_georss_item.php");
+
+/**
+ * Creates an RSS Feed.
+ */
+class GeoRss extends Rss {
+
+ protected function createItem () {
+ return new GeoRssItem();
+ }
+
+ protected function getNamespaceString () {
+ return parent::getNamespaceString() .
+ ' xmlns:georss="http://www.georss.org/georss"';
+ }
+}
+?>
Added: branches/3_dev/core/lib/class_georss_factory.php
===================================================================
--- branches/3_dev/core/lib/class_georss_factory.php (rev 0)
+++ branches/3_dev/core/lib/class_georss_factory.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,51 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/class_rss_factory.php";
+require_once dirname(__FILE__) . "/class_georss.php";
+
+class GeoRssFactory extends RssFactory {
+
+ protected function createRss () {
+ $rss = new GeoRss();
+ return $rss;
+ }
+
+ protected function createRssItem () {
+ $rssItem = new GeoRssItem();
+ return $rssItem;
+ }
+
+ protected function parseItem ($node, $item) {
+
+ $item = parent::parseItem($node, $item);
+
+ foreach ($node->childNodes as $childNode) {
+ switch ($childNode->tagName) {
+ case "georss:box":
+ $coordinateString = trim($childNode->nodeValue);
+ $coordinateArray = explode(" ", $coordinateString);
+
+ if (count($coordinateArray) === 4) {
+ $bbox = new Mapbender_bbox(
+ floatval($coordinateArray[0]),
+ floatval($coordinateArray[1]),
+ floatval($coordinateArray[2]),
+ floatval($coordinateArray[3]),
+ "EPSG:4326"
+ );
+ $item->setBbox($bbox);
+ }
+ break;
+ }
+ }
+ return $item;
+ }
+}
+
+?>
Added: branches/3_dev/core/lib/class_georss_geometry.php
===================================================================
--- branches/3_dev/core/lib/class_georss_geometry.php (rev 0)
+++ branches/3_dev/core/lib/class_georss_geometry.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,337 @@
+<?php
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#TODO:Check if the following line is enough:
+#require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_Json.php");
+require_once(dirname(__FILE__)."/class_gml2.php");
+
+class geoRSS {
+ var $doc;
+ var $importItems = array("title","link","description");
+ var $targetEPSG;
+ function parseFile($req){
+ #$data = implode("",file($req));
+ $x = new connector($req);
+ $data = $x->file;
+ $data = $this->removeWhiteSpace($data);
+ if($data=="")
+ return false;
+ return $this->parseXML($data);
+ #$e = new mb_exception("data = ".$data);
+ }
+
+ /**
+ * Set the Rss Elements that should go to the property tags of geoJSON
+ * default is "title","link" and "description"
+ */
+ public function setImportTags($tags){
+ $this->importItems = $tags;
+ }
+
+ function parseXML($data) {
+ $this->doc = $data;
+ return $this->toGeoJSON();
+ }
+
+ function removeWhiteSpace ($string) {
+ return preg_replace("/\>(\s)+\</", "><", trim($string));
+ }
+
+ function toGeoJSON () {
+ $rssDoc = new SimpleXMLElement($this->doc);
+
+ $rssDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+ $rssDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+ $rssDoc->registerXPathNamespace('georss', 'http://www.georss.org/georss');
+ #for ingrid - portalu georss
+ $rssDoc->registerXPathNamespace('ingrid', 'http://www.portalu.de/opensearch/extension/1.0');
+
+ // build feature collection
+ $featureCollection = new FeatureCollection();
+
+ // elements of rss document
+ $rssItems = $rssDoc->xpath("//item");
+
+ if(count($rssItems)>0){
+ foreach($rssItems as $item){
+ $rssItem_dom = dom_import_simplexml($item);
+
+ $feature = new geoRSSItem();
+ $feature->targetEPSG = $this->targetEPSG;
+ $feature->parse($rssItem_dom, $this->importItems);
+ if (isset($feature->geometry) && $feature->geometry!==false) {
+ $featureCollection->addFeature($feature);
+ }
+ }
+
+ return $featureCollection->toGeoJSON();
+ }
+ else{
+ return "{'errorMessage':'Kein Ergebnis'}";
+ }
+ }
+}
+
+class geoRSSItem extends Feature{
+ var $targetEPSG;
+ #$this->targetEPSG='4326';
+ public function parse($domNode, $importItems) {
+ $currentSibling = $domNode->firstChild;
+
+ while ($currentSibling) {
+ $tag = $currentSibling->nodeName;
+ if(in_array($tag, $importItems)){
+ $this->properties[$tag] = $currentSibling->nodeValue;
+ }
+ else{
+ switch ($tag) {
+ case "georss:where":
+ $this->parseGML($currentSibling);
+ break;
+ case "georss:point":
+ $this->geometry = new geoRSSPoint();
+ $this->geometry->targetEPSG = $this->targetEPSG;
+ $this->geometry->parsePoint($currentSibling);
+ break;
+ case "georss:line":
+ $this->geometry = new geoRSSLine();
+ $this->geometry->targetEPSG = $this->targetEPSG;
+ $this->geometry->parseLine($currentSibling);
+ break;
+ case "georss:box":
+ $this->geometry = new geoRSSBox();
+ $this->geometry->targetEPSG = $this->targetEPSG;
+ $this->geometry->parseBox($currentSibling);
+ break;
+ case "georss:polygon":
+ $this->geometry = new geoRSSPolygon();
+ $this->geometry->targetEPSG = $this->targetEPSG;
+ $this->geometry->parsePolygon($currentSibling);
+ break;
+ case "geo:point":
+ $this->geometry = new geoPoint();
+ $this->geometry->parsePoint($currentSibling);
+ break;
+ case "geo:lat":
+ if(!$this->geometry)
+ $this->geometry = new geoPoint();
+ $this->geometry->targetEPSG = $this->targetEPSG;
+ $this->geometry->parseLat($currentSibling);
+ break;
+ case "geo:long":
+ if(!$this->geometry)
+ $this->geometry = new geoPoint();
+ $this->geometry->targetEPSG = $this->targetEPSG;
+ $this->geometry->parseLong($currentSibling);
+ break;
+ default:
+ break;
+ }
+ }
+ $currentSibling = $currentSibling->nextSibling;
+ }
+ }
+
+ function parseGML($domNode){
+ $currentSibling = $domNode->firstChild;
+
+ while ($currentSibling) {
+ $geomType = $currentSibling->nodeName;
+ switch ($geomType) {
+ case "gml:Polygon" :
+ $this->geometry = new GMLPolygon();
+ $this->geometry->parsePolygon($currentSibling);
+ break;
+ case "gml:LineString" :
+ $this->geometry = new GMLLine();
+ $this->geometry->parseLine($currentSibling);
+ break;
+ case "gml:Point" :
+ $this->geometry = new GMLPoint();
+ $this->geometry->parsePoint($currentSibling);
+ break;
+ case "gml:MultiLineString" :
+ $this->geometry = new GMLMultiLine();
+ $this->geometry->parseMultiLine($currentSibling);
+ break;
+ case "gml:MultiPolygon" :
+ $this->geometry = new GMLMultiPolygon();
+ $this->geometry->parseMultiPolygon($currentSibling);
+ break;
+ case "gml:Envelope" :
+ $this->geometry = new GMLEnvelope();
+ $this->geometry->parseEnvelope($currentSibling);
+ default:
+ break;
+ }
+ $currentSibling = $currentSibling->nextSibling;
+ }
+ }
+}
+
+class geoRSSPoint extends GMLPoint{
+ var $targetEPSG;
+ public function parsePoint($domNode){
+ list($y, $x) = explode(" ", $domNode->nodeValue);
+ if ($this->targetEPSG != '4326') {
+ $tCoords = transform($x, $y,'4326', $this->targetEPSG);
+ $x = $tCoords["x"];
+ $y = $tCoords["y"];
+ $this->setPoint($x, $y);
+ }
+ else {
+ $this->setPoint($x, $y);
+ }
+ }
+}
+
+class geoPoint extends GMLPoint{
+ var $targetEPSG;
+ public function parsePoint($domNode){
+ $currentSibling = $domNode->firstChild;
+ while ($currentSibling) {
+ switch ($currentSibling->nodeName){
+ case "geo:lat":
+ $this->parseLat($currentSibling);
+ break;
+ case "geo:lon":
+ $this->parseLon($currentSibling);
+ break;
+ }
+ $currentSibling = $currentSibling->nextSibling;
+ }
+ }
+ public function parseLat($node){
+ if(!$this->point)
+ $this->point=array();
+ if ($this->targetEPSG != '4326') {
+ $tCoords = transform(0, $node->nodeValue,'4326', $this->targetEPSG);
+
+ $this->point["y"] = $tCoords["y"];
+
+ }
+ else {
+ $this->point["y"] = $node->nodeValue;
+ }
+ }
+ public function parseLong($node){
+ if(!$this->point)
+ $this->point=array();
+ if ($this->targetEPSG != '4326') {
+ $tCoords = transform($node->nodeValue, 0, '4326', $this->targetEPSG);
+
+ $this->point["x"] = $tCoords["x"];
+
+ }
+ else {
+ $this->point["x"] = $node->nodeValue;
+ }
+ }
+}
+
+
+
+class geoRSSLine extends GMLLine{
+ var $targetEPSG;
+ public function parseLine ($domNode) {
+ $cnt = 0;
+ $y = 0;
+ foreach(explode(' ',$domNode->nodeValue) as $cord){
+ if($cnt % 2)
+ $this->addPoint($cord, $y);
+ $y = $cord;
+ $cnt++;
+ }
+ }
+}
+
+class geoRSSPolygon extends GMLPolygon{
+ var $targetEPSG;
+ public function parsePolygon ($domNode) {
+ $cnt = 0;
+ $y = 0;
+ foreach(explode(' ',$domNode->nodeValue) as $cord){
+ if($cnt % 2)
+ $this->addPoint($cord, $y);
+ $y = $cord;
+ $cnt++;
+ }
+ }
+}
+
+class geoRSSBox extends GMLPolygon{
+ var $targetEPSG;
+ public function parseBox ($domNode) {
+ list($x1,$y1,$x2,$y2) = explode(' ',$domNode->nodeValue);
+ if ($this->targetEPSG != '4326') {
+ $tCoords = transform($x1, $y1,'4326', $this->targetEPSG);
+ $x1 = $tCoords["x"];
+ $y1 = $tCoords["y"];
+ $tCoords = transform($x2, $y2,'4326', $this->targetEPSG);
+ $x2 = $tCoords["x"];
+ $y2 = $tCoords["y"];
+ }
+ $this->addPoint($x1, $y1);
+ $this->addPoint($x1, $y2);
+ $this->addPoint($x2, $y2);
+ $this->addPoint($x2, $y1);
+ $this->addPoint($x1, $y1);
+ }
+}
+function transform ($x, $y, $oldEPSG, $newEPSG) {
+ if (is_null($x) || !is_numeric($x) ||
+ is_null($y) || !is_numeric($y) ||
+ is_null($oldEPSG) || !is_numeric($oldEPSG) ||
+ is_null($newEPSG) || !is_numeric($newEPSG)) {
+ return null;
+ }
+ if(SYS_DBTYPE=='pgsql'){
+ $con = db_connect(DBSERVER, OWNER, PW);
+ $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$x."
+".$y.")',".$oldEPSG."),".$newEPSG.")) as minx";
+ $resMinx = db_query($sqlMinx);
+ $minx = floatval(db_result($resMinx,0,"minx"));
+
+ $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$x."
+".$y.")',".$oldEPSG."),".$newEPSG.")) as miny";
+ $resMiny = db_query($sqlMiny);
+ $miny = floatval(db_result($resMiny,0,"miny"));
+
+ }else{
+ $con_string = "host=" . GEOS_DBSERVER . " port=" . GEOS_PORT .
+ " dbname=" . GEOS_DB . "user=" . GEOS_OWNER .
+ "password=" . GEOS_PW;
+ $con = pg_connect($con_string) or die ("Error while connecting
+database");
+
+ $sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$x."
+".$y.")',".$oldEPSG."),".$newEPSG.")) as minx";
+ $resMinx = pg_query($con,$sqlMinx);
+ $minx = floatval(pg_fetch_result($resMinx,0,"minx"));
+
+ $sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$x."
+".$y.")',".$oldEPSG."),".$newEPSG.")) as miny";
+ $resMiny = pg_query($con,$sqlMiny);
+ $miny = floatval(pg_fetch_result($resMiny,0,"miny"));
+ }
+ return array("x" => $minx, "y" => $miny);
+}
+?>
Added: branches/3_dev/core/lib/class_georss_item.php
===================================================================
--- branches/3_dev/core/lib/class_georss_item.php (rev 0)
+++ branches/3_dev/core/lib/class_georss_item.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,42 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/class_georss.php";
+require_once dirname(__FILE__) . "/class_bbox.php";
+
+class GeoRssItem extends RssItem {
+ private $bbox;
+
+ public function setBbox ($bbox) {
+ if (is_a($bbox, "Mapbender_bbox")) {
+ $this->bbox = $bbox;
+ return true;
+ }
+ new mb_exception(__FILE__ .
+ ": setBbox(): parameter not a Mapbender_bbox!");
+ return false;
+ }
+
+ public function getBbox () {
+ return $this->bbox;
+ }
+
+ protected function getItemString () {
+ $str = parent::getItemString();
+ if (is_a($this->bbox, "Mapbender_bbox")) {
+ $str .= "<georss:box>" .
+ $this->bbox->min->x . " " .
+ $this->bbox->min->y . " " .
+ $this->bbox->max->x . " " .
+ $this->bbox->max->y .
+ "</georss:box>\n";
+ }
+ return $str;
+ }
+}
+?>
Added: branches/3_dev/core/lib/class_gml2.php
===================================================================
--- branches/3_dev/core/lib/class_gml2.php (rev 0)
+++ branches/3_dev/core/lib/class_gml2.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,994 @@
+<?php
+# $Id: class_gml2.php 3099 2008-10-02 15:29:23Z nimix $
+# http://www.mapbender.org/index.php/class_gml2.php
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+class gml2 {
+ var $geomtype_point = 'Point';
+ var $geomtype_polygon = 'Polygon';
+ var $geomtype_line = 'LineString';
+ var $geomtype_multipolygon = 'MultiPolygon';
+ var $geomtype_multiline = 'MultiLine';
+ var $geometries = array();
+ var $member = -1;
+ var $geomtype = array();
+ var $keys = array();
+ var $values = array();
+ var $geometry = array();
+ var $bbox = array();
+ var $doc;
+ var $geomFeaturetypeElement = null;
+
+
+ function gml2(){
+ $this->geometries = array($this->geomtype_point, $this->geomtype_polygon, $this->geomtype_line, $this->geomtype_multipolygon, $this->geomtype_multiline);
+ }
+ function getGml($req){
+ $x = new connector($req);
+ return $x->file;
+ }
+
+ function parseFile($req){
+ #$data = implode("",file($req));
+ $x = new connector($req);
+ $data = $x->file;
+ $data = $this->removeWhiteSpace($data);
+ $this->parseXML($data);
+ #$e = new mb_exception("data = ".$data);
+ }
+
+ function parseXML($data) {
+ if (func_num_args() == 2) {
+ $this->geomFeaturetypeElement = func_get_arg(1);
+ }
+ $this->doc = $this->removeWhiteSpace($data);
+ return $this->toGeoJSON();
+ }
+
+ function removeWhiteSpace ($string) {
+ return preg_replace("/\>(\s)+\</", "><", trim($string));
+ }
+
+ function sepNameSpace($s){
+ $c = mb_strpos($s,":");
+ if($c>0){
+ return mb_substr($s,$c+1);
+ }
+ else{
+ return $s;
+ }
+ }
+
+ function toGeoJSON () {
+ $gmlDoc = new SimpleXMLElement($this->doc);
+
+ $gmlDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+ $gmlDoc->registerXPathNamespace('wfs', 'http://www.opengis.net/wfs');
+ $gmlDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+
+ // build feature collection
+ $featureCollection = new FeatureCollection();
+
+ // segments of the featzreCollection
+ $gmlFeatureMembers = $gmlDoc->xpath("//gml:featureMember");
+
+ if(count($gmlFeatureMembers)>0){
+ $cnt=0;
+ foreach ($gmlFeatureMembers as $gmlFeatureMember) {
+ $featureMember_dom = dom_import_simplexml($gmlFeatureMember);
+
+ $feature = new Feature();
+ if ($this->geomFeaturetypeElement != null) {
+ $feature->parse($featureMember_dom, $this->geomFeaturetypeElement);
+ }
+ else {
+ $feature->parse($featureMember_dom);
+ }
+ if (isset($feature->geometry)) {
+ $featureCollection->addFeature($feature);
+ }
+ $cnt++;
+ }
+
+ return $featureCollection->toGeoJSON();
+ }
+ else{
+ return "{}";
+ }
+ }
+
+
+ /**
+ * Exports the file to SHP.
+ *
+ * @param string $filenamePrefix the filename without an ending like .shp
+ */
+ function toShape ($filenamePrefix) {
+ $unique = TMPDIR . "/" . $filenamePrefix;
+ $fShape = $unique.".shp";
+ $fGml = $unique.".gml";
+// $pathOgr = '/appserver/postgresql/templates/postgresql824/bin/ogr2ogr';
+ $pathOgr = '/usr/bin/ogr2ogr';
+// $pathOgr = OGR2OGR_PATH;
+ $w = $this->toFile($fGml);
+ // - get EPSC-Code from GML-File--
+
+ $data = file_get_contents($fGml);//
+ $gmlDoc = new SimpleXMLElement($data);
+
+ $gmlDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
+ $gmlDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+
+ $gmlBboxes = $gmlDoc->xpath("//gml:Box"); //<gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
+
+ if(count($gmlBboxes)>0){
+ $bbox_str = $gmlBboxes[0]['srsName'];
+ $pos_raute = strpos($bbox_str, '#');
+ $epsg = substr($bbox_str, $pos_raute+1);
+
+ } else {
+ $e = new mb_exception("class_gml2.php:toShape() => no EPSG in GML(" . $fGml . ").");
+ }
+ // ---
+
+
+ $str_ogr = $pathOgr.' -a_srs EPSG:'.$epsg.' -f "ESRI Shapefile" "'.$fShape.'" '.$fGml;
+ $e = new mb_exception("ogr-Befehl:".$str_ogr);
+
+ $exec = $pathOgr.' -a_srs EPSG:'.$epsg.' -f "ESRI Shapefile" "'.$fShape.'" '.$fGml;
+
+
+
+ //$exec = $pathOgr.' -f "ESRI Shapefile" "'.$fShape.'" '.$fGml;
+ exec($exec);
+
+ $exec = 'zip -j '.$unique.' '.$unique.'.shp '.$unique.'.dbf '.$unique.'.shx '.$unique.'.gfs '.$unique.'.gml '.$unique.'.prj ';
+ exec($exec);
+
+ $exec = 'rm -f '.$unique.' '.$unique.'.shp '.$unique.'.dbf '.$unique.'.shx '.$unique.'.gfs '.$unique.'.gml '.$unique.'.prj ';
+ exec($exec);
+
+ $exec = 'chmod 777 '.$unique.'.*';
+ exec($exec);
+ //echo "<a href='../tmp/".$unique.".zip'>Download ".$prefix."<a>";
+ }
+
+ /**
+ * Writes a file containing the GML.
+ *
+ * @param string $path the path to the file.
+ * @param string $path the path to the file.
+ * @return bool true if the file could be saved; else false.
+ */
+ function toFile ($file) {
+ $handle = fopen($file, "w");
+ if (!$handle) {
+ $e = new mb_exception("class_gml2.php: Filehandler error (" . $file . ").");
+ return false;
+ }
+ if (!fwrite($handle,$this->__toString())) {
+ $e = new mb_exception("class_gml2.php: Could not write file (" . $file . ").");
+ fclose($handle);
+ return false;
+ }
+ fclose($handle);
+ return true;
+ }
+
+ function __toString () {
+ return $this->doc;
+ }
+
+
+
+ /**
+ * @deprecated
+ */
+ function parsegml($req){
+ #$data = implode("",file($req));
+ $x = new connector($req);
+ $this->parse_xml($x->file);
+ }
+
+ /**
+ * @deprecated
+ */
+ function parse_xml($data){
+
+
+ $this->doc = $data;
+
+ $section = false;
+ $geom = false;
+ $boundedBy = false;
+ $coordinates = false;
+ $el = -1;
+ $parser = xml_parser_create(CHARSET);
+ xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
+ xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
+ xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET);
+ xml_parse_into_struct($parser,$data,$values,$tags);
+ $code = xml_get_error_code ($parser);
+ if ($code) {
+ $line = xml_get_current_line_number($parser);
+ $mb_exception = new mb_exception(xml_error_string($code) . " in line " . $line);
+ }
+ xml_parser_free($parser);
+
+ foreach ($values as $element) {
+ #$e = new mb_exception($element[tag]);
+ if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("boundedBy") && $element[type] == "open"){
+ $boundedBy = true;
+ }
+ if ($boundedBy) {
+ if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("coordinates")){
+ $this->bbox = explode(",", str_replace(",,","",str_replace(" ",",",trim($element[value]))));
+ $boundedBy=false;
+ }
+ }
+ if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("featureMember") && $element[type] == "open"){
+ $this->member++;
+ $this->keys[$this->member] = array();
+ $this->value[$this->member] = array();
+ $this->geometry[$this->member] = array();
+ $section = true;
+ $cnt_geom = 0;
+ }
+ if($section == true){
+ if( in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "open"){
+ $geom = true;
+ $this->geomtype[$this->member] = $this->sepNameSpace($element[tag]);
+ }
+ else if(in_array($this->sepNameSpace($element[tag]),$this->geometries) && $element[type] == "close"){
+ $cnt_geom++;
+ $geom = false;
+ }
+ if($geom == true){
+ if (strtoupper($this->sepNameSpace($element[tag])) == strtoupper("coordinates")) {
+ $this->geometry[$this->member][$cnt_geom] = str_replace(",,","",str_replace(" ",",",trim($element[value])));
+ $coordinates = true;
+ // XXX: Increment counter to get all geometries of a feature member,
+ // comment it out to only show first geometry of featuremember
+ $cnt_geom++;
+ }
+ else if (!$coordinates && trim($element[value])) {
+ $coords = str_replace(",,","",str_replace(" ",",",trim($element[value])));
+ $tmp_array = explode(",", $coords);
+ if (count($tmp_array > 1)) {
+ $this->geometry[$this->member][$cnt_geom] = $coords;
+ $coordinates = true;
+ // XXX: Increment counter to get all geometries of a feature member,
+ // comment it out to only show first geometry of featuremember
+ $cnt_geom++;
+ }
+ }
+ }
+ else if(strtoupper($this->sepNameSpace($element[tag])) == strtoupper("featureMember") && $element[type] == "close"){
+ $section = false;
+ $el = -1;
+ }
+ else{
+ $el++;
+ $this->values[$this->member][$el] = $element[value];
+ $this->keys[$this->member][$el] = $element[tag];
+ }
+ }
+ }
+ }
+
+ /**
+ * @deprecated
+ */
+ function getMemberCount(){
+ return ($this->member+1);
+ }
+
+ /**
+ * @deprecated
+ */
+ function getValueBySeparatedKey($memberCount,$keyName){
+ for($i=0; $i<count($this->keys[$memberCount]); $i++){
+ if($this->sepNameSpace($this->keys[$memberCount][$i]) == $keyName){
+ return $this->values[$memberCount][$i];
+ }
+ }
+ }
+
+ /**
+ * @deprecated
+ */
+ function getValueByKey($memberCount,$keyName){
+ for($i=0; $i<count($this->keys[$memberCount]); $i++){
+ if($this->keys[$memberCount][$i] == $keyName){
+ return $this->values[$memberCount][$i];
+ }
+ }
+ }
+
+ /**
+ * @deprecated
+ */
+ function getXfromMemberAsString($memberCount,$geomCount){
+ $t = explode(",",$this->geometry[$memberCount][$geomCount]);
+ $x = array();
+ for($i=0; $i<(count($t)-1); $i=$i+2){
+ array_push($x,$t[$i]);
+ }
+ return implode(",",$x);
+ }
+
+ /**
+ * @deprecated
+ */
+ function getYfromMemberAsString($memberCount,$geomCount){
+ $t = explode(",",$this->geometry[$memberCount][$geomCount]);
+ $y = array();
+ for($i=1; $i<=(count($t)-1); $i=$i+2){
+ array_push($y,$t[$i]);
+ }
+ return implode(",",$y);
+ }
+
+ /**
+ * @deprecated
+ */
+ function getGeometriesFromMember($memberCount){
+ return $this->geometry[$memberCount];
+ }
+
+ /**
+ * @deprecated
+ */
+ function getGeometryTypeFromMember($memberCount){
+ return $this->geomtype[$memberCount];
+ }
+
+ /**
+ * @deprecated
+ */
+ function exportGeometriesToJS ($isInFrame) {
+ $prefix = "";
+ if ($isInFrame == true) {
+ $prefix = "parent.";
+ }
+ $js = "";
+ $js .= "var geom = new ".$prefix."GeometryArray();\n";
+ for ($i=0; $i<count($this->geometry); $i++) {
+ $js .= $this->exportMemberToJS($i, $isInFrame);
+ $js .= "geom.addCopy(q);\n";
+ }
+ return $js;
+ }
+
+ /**
+ * @deprecated
+ */
+ function exportMemberToJS ($i, $isInFrame) {
+ $prefix = "";
+ if ($isInFrame == true) {
+ $prefix = "parent.";
+ }
+ $js = "";
+ if ($this->getGeometryTypeFromMember($i) == $this->geomtype_point) {
+ $js .= "var current_geomtype = ".$prefix."geomType.point;\n";
+ }
+ elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_line || $this->getGeometryTypeFromMember($i) == $this->geomtype_multiline) {
+ $js .= "var current_geomtype = ".$prefix."geomType.line;\n";
+ }
+ elseif ($this->getGeometryTypeFromMember($i) == $this->geomtype_polygon || $this->getGeometryTypeFromMember($i) == $this->geomtype_multipolygon) {
+ $js .= "var current_geomtype = ".$prefix."geomType.polygon;\n";
+ }
+ else {
+ $e = new mb_notice("unknown geometry type: '".$this->getGeometryTypeFromMember($i)."' or no geometry existing");
+ return "";
+ }
+
+ $js .= "var q = new ".$prefix."MultiGeometry(current_geomtype);\n";
+
+ for ($j=0; $j<count($this->geometry[$i]); $j++) {
+ $js .= "q.addGeometry(current_geomtype);\n";
+
+ $x_array = explode(",", $this->getXfromMemberAsString($i, $j));
+ $y_array = explode(",", $this->getYfromMemberAsString($i, $j));
+
+ for ($k=0; $k<count($x_array); $k++) {
+ $js .= "q.get(-1).addPointByCoordinates(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));\n";
+ //$js .= "alert(parseFloat(".$x_array[$k]."), parseFloat(".$y_array[$k]."));";
+ }
+ $js .= "q.get(-1).close();\n";
+ }
+// $js .= "alert(q);\n";
+ return $js;
+ }
+
+}
+
+
+
+
+class FeatureCollection {
+ var $type = "FeatureCollection";
+ var $featureArray = array();
+
+ public function __construct() {
+
+ }
+
+ public function addFeature ($aFeature) {
+ array_push($this->featureArray, $aFeature);
+ }
+
+ public function toGeoJSON () {
+ $str = "";
+ $len = count($this->featureArray);
+ if ($len > 0) {
+ $str .= "{\"type\": \"FeatureCollection\", \"features\": [";
+ for ($i=0; $i < $len; $i++) {
+ if ($i > 0) {
+ $str .= ",";
+ }
+ $str .= $this->featureArray[$i]->toGeoJSON();
+ }
+ $str .= "]}";
+ }
+ return $str;
+ }
+}
+
+class Feature {
+ var $type = "Feature";
+ var $fid;
+ var $geometry = false;
+ var $properties = array();
+ var $geomFeaturetypeElement = null;
+
+ public function __construct() {
+ }
+
+ function sepNameSpace($s){
+ list($ns,$FeaturePropertyName) = split(":",$s);
+ $nodeName = array('ns' => $ns, 'value' => $FeaturePropertyName);
+ return $nodeName;
+ }
+
+ /**
+ * Parses the feature segment of a GML and stores the geometry in the
+ * $geometry variable of the class.
+ *
+ * Example of a feature segment of a GML.
+ * <gml:featureMember>
+ * <ms:ROUTE fid="ROUTE.228168">
+ * <gml:boundedBy>
+ * <gml:Box srsName="EPSG:31466">
+ * <gml:coordinates>2557381.0,5562371.1 2557653.7,5562526.0</gml:coordinates>
+ * </gml:Box>
+ * </gml:boundedBy>
+ * <ms:geometry>
+ * <gml:LineString>
+ * <gml:coordinates>
+ * 2557380.97,5562526 2557390.96,
+ * 5562523.22 2557404.03,5562518.2 2557422.31,
+ * 5562512 2557437.16,5562508.37 2557441.79,
+ * 5562507.49 2557454.31,5562505.1 2557464.27,
+ * 5562503.97 2557473.24,5562502.97 2557491.67,
+ * 5562502.12 2557505.65,5562502.43 2557513.78,
+ * 5562501.12 2557520.89,5562498.79 2557528.5,
+ * 5562495.07 2557538.9,5562488.91 2557549.5,
+ * 5562483.83 2557558.55,5562476.61 2557569.07,
+ * 5562469.82 2557576.61,5562462.72 2557582.75,
+ * 5562457.92 2557588.57,5562452.56 2557590.38,
+ * 5562449.69 2557593.57,5562445.07 2557596.17,
+ * 5562441.31 2557601.71,5562433.93 2557612.97,
+ * 5562421.03 2557626,5562405.33 2557639.66,
+ * 5562389.75 2557653.69,5562371.12
+ * </gml:coordinates>
+ * </gml:LineString>
+ * </ms:geometry>
+ * <code>354</code>
+ * <Verkehr>0</Verkehr>
+ * <rlp>t</rlp>
+ * </ms:ROUTE>
+ * </gml:featureMember>
+ *
+ * @return void
+ * @param $domNode DOMNodeObject the feature tag of the GML
+ * (<gml:featureMember> in the above example)
+ */
+ public function parse($domNode) {
+ if (func_num_args() == 2) {
+ $this->geomFeaturetypeElement = func_get_arg(1);
+ }
+
+ $currentSibling = $domNode->firstChild;
+
+ $this->fid = $currentSibling->getAttribute("fid");
+
+ $currentSibling = $currentSibling->firstChild;
+
+ while ($currentSibling) {
+
+ $name = $currentSibling->nodeName;
+ $value = $currentSibling->nodeValue;
+
+ $namespace = $this->sepNameSpace($name);
+ $ns = $namespace['ns'];
+ $columnName = $namespace['value'];
+ $isGeomColumn = ($this->geomFeaturetypeElement == null || $columnName == $this->geomFeaturetypeElement);
+
+ // check if this node is a geometry node.
+ // however, even if it is a property node,
+ // it has a child node, the text node!
+ // So we might need to do something more
+ // sophisticated here...
+ if ($currentSibling->hasChildNodes() && $isGeomColumn){
+ $geomNode = $currentSibling->firstChild;
+ $geomType = $geomNode->nodeName;
+ switch ($geomType) {
+ case "gml:Polygon" :
+ $this->geometry = new GMLPolygon();
+ $this->geometry->parsePolygon($geomNode);
+ break;
+ case "gml:LineString" :
+ $this->geometry = new GMLLine();
+ $this->geometry->parseLine($geomNode);
+ break;
+ case "gml:Point" :
+ $this->geometry = new GMLPoint();
+ $this->geometry->parsePoint($geomNode);
+ break;
+ case "gml:MultiLineString" :
+ $this->geometry = new GMLMultiLine();
+ $this->geometry->parseMultiLine($geomNode);
+ break;
+ case "gml:MultiPolygon" :
+ $this->geometry = new GMLMultiPolygon();
+ $this->geometry->parseMultiPolygon($geomNode);
+ break;
+ case "gml:Envelope" :
+ $this->geometry = new GMLEnvelope();
+ $this->geometry->parseEnvelope($geomNode);
+ break;
+ default:
+ $this->properties[$columnName] = $value;
+ break;
+ }
+ }
+ else {
+ $this->properties[$columnName] = $value;
+ }
+
+ $currentSibling = $currentSibling->nextSibling;
+ }
+ }
+
+ public function toGeoJSON () {
+ $str = "";
+ $str .= "{\"type\":\"Feature\", \"id\":\"".$this->fid."\", \"geometry\": ";
+ if ($this->geometry) {
+ $str .= $this->geometry->toGeoJSON();
+ }
+ else {
+ $str .= "\"\"";
+ }
+
+
+ $prop = array();
+
+ $str .= ", \"properties\": ";
+ $cnt = 0;
+ foreach ($this->properties as $key => $value) {
+ $prop[$key] = $value;
+ $cnt ++;
+ }
+
+ $json = new Mapbender_JSON();
+ $str .= $json->encode($prop);
+ $str .= "}";
+
+ return $str;
+ }
+}
+
+class GMLLine {
+
+ var $pointArray = array();
+
+ public function __construct() {
+
+ }
+
+ public function parseLine ($domNode) {
+ $currentSibling = $domNode->firstChild;
+ while ($currentSibling) {
+
+ foreach(explode(' ',$currentSibling->nodeValue) as $cords){
+ list($x,$y,$z) = explode(',',$cords);
+ $this->addPoint($x, $y);
+ }
+ $currentSibling = $currentSibling->nextSibling;
+ }
+ }
+
+ protected function addPoint ($x, $y) {
+ array_push($this->pointArray, array("x" => $x, "y" => $y));
+ }
+
+ public function toGeoJSON () {
+ $numberOfPoints = count($this->pointArray);
+ $str = "";
+ if ($numberOfPoints > 0) {
+ $str .= "{\"type\": \"LineString\", \"coordinates\":[";
+ for ($i=0; $i < $numberOfPoints; $i++) {
+ if ($i > 0) {
+ $str .= ",";
+ }
+ $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ }
+ $str .= "]}";
+ }
+ else {
+ $e = new mb_exception("GMLLine: toGeoJSON: this point is null.");
+ }
+ return $str;
+ }
+}
+
+class GMLPoint {
+
+ var $point;
+
+ public function __construct() {
+
+ }
+
+ public function parsePoint ($domNode) {
+ $currentSibling = $domNode->firstChild;
+ while ($currentSibling) {
+ list($x, $y, $z) = explode(",", $currentSibling->nodeValue);
+ $this->setPoint($x, $y);
+ $currentSibling = $currentSibling->nextSibling;
+ }
+ }
+
+ protected function setPoint ($x, $y) {
+# echo "x: " . $x . " y: " . $y . "\n";
+ $this->point = array("x" => $x, "y" => $y);
+ }
+
+ public function toGeoJSON () {
+ $str = "";
+ if ($this->point) {
+ $str .= "{\"type\": \"Point\", \"coordinates\":";
+ $str .= "[".$this->point["x"].",".$this->point["y"]."]";
+ $str .= "}";
+ }
+ else {
+ $e = new mb_exception("GMLPoint: toGeoJSON: this point is null.");
+ }
+ return $str;
+ }
+}
+
+class GMLPolygon {
+
+ var $pointArray = array();
+ var $innerRingArray = array();
+
+ public function __construct() {
+
+ }
+
+ public function parsePolygon ($domNode) {
+ $simpleXMLNode = simplexml_import_dom($domNode);
+
+ $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+
+ $allCoords = $simpleXMLNode->xpath("gml:outerBoundaryIs/gml:LinearRing/gml:coordinates");
+
+ $cnt=0;
+ foreach ($allCoords as $Coords) {
+ $coordsDom = dom_import_simplexml($Coords);
+
+// $name = $coordsDom->nodeName;
+// $value = $coordsDom->nodeValue;
+// echo "===> name: ".$name. ", Value: ".$value."<br>";
+
+ foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+
+ list($x,$y,$z) = explode(',',$pointCoords);
+ $this->addPoint($x, $y);
+ }
+
+ $cnt++;
+ }
+
+ $innerRingNodeArray = $simpleXMLNode->xpath("gml:innerBoundaryIs/gml:LinearRing");
+ if ($innerRingNodeArray) {
+ $ringCount = 0;
+ foreach ($innerRingNodeArray as $ringNode) {
+ $coordinates = $ringNode->xpath("gml:coordinates");
+ foreach ($coordinates as $coordinate) {
+ $coordsDom = dom_import_simplexml($coordinate);
+
+ foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+
+ list($x,$y,$z) = explode(',',$pointCoords);
+ $this->addPointToRing($ringCount, $x, $y);
+ }
+ }
+ $ringCount++;
+ }
+ }
+ }
+
+ protected function addPoint ($x, $y) {
+ array_push($this->pointArray, array("x" => $x, "y" => $y));
+ }
+
+ protected function addPointToRing ($i, $x, $y) {
+ if (count($this->innerRingArray) <= $i) {
+ array_push($this->innerRingArray, array());
+ }
+ $index = count($this->innerRingArray);
+ $currentIndex = ($i < $index ? $i : $index);
+ array_push($this->innerRingArray[$currentIndex], array("x" => $x, "y" => $y));
+ }
+
+ public function toGeoJSON () {
+ $numberOfPoints = count($this->pointArray);
+ $str = "";
+ if ($numberOfPoints > 0) {
+ $str .= "{\"type\": \"Polygon\", \"coordinates\":[[";
+ for ($i=0; $i < $numberOfPoints; $i++) {
+ if ($i > 0) {
+ $str .= ",";
+ }
+ $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]";
+ }
+ $str .= "]";
+
+ for ($i=0; $i < count($this->innerRingArray); $i++) {
+ $str .= ",[";
+ for ($j=0; $j < count($this->innerRingArray[$i]); $j++) {
+ if ($j > 0) {
+ $str .= ",";
+ }
+ $str .= "[".$this->innerRingArray[$i][$j]["x"].",".$this->innerRingArray[$i][$j]["y"]."]";
+ }
+ $str .= "]";
+ }
+ $str .= "]}";
+ }
+ else {
+ $e = new mb_exception("GMLPolygon: toGeoJSON: this point is null.");
+ }
+ return $str;
+ }
+}
+
+class GMLEnvelope extends GMLPolygon{
+/* <gml:Envelope>
+ <gml:lowerCorner>42.943 -71.032</gml:lowerCorner>
+ <gml:upperCorner>43.039 -69.856</gml:upperCorner>
+ </gml:Envelope>
+*/
+ public function parseEnvelope ($domNode) {
+ $corner1 = $domNode->firstChild;
+ $corner2 = $corner1->nextSibling;
+
+ list($y1,$x1) = explode(' ',$corner1->nodeValue);
+ list($y2,$x2) = explode(' ',$corner2->nodeValue);
+
+ $this->addPoint($x1, $y1);
+ $this->addPoint($x1, $y2);
+ $this->addPoint($x2, $y2);
+ $this->addPoint($x2, $y1);
+ $this->addPoint($x1, $y1);
+ }
+}
+
+
+
+class GMLMultiLine {
+
+ var $lineArray = array();
+
+ public function __construct() {
+
+ }
+
+ public function parseMultiLine ($domNode) {
+ $simpleXMLNode = simplexml_import_dom($domNode);
+
+ $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+
+ $allCoords = $simpleXMLNode->xpath("gml:lineStringMember/gml:LineString/gml:coordinates");
+
+ $cnt=0;
+ foreach ($allCoords as $Coords) {
+
+ $this->lineArray[$cnt] = array();
+
+ $coordsDom = dom_import_simplexml($Coords);
+
+// $name = $coordsDom->nodeName;
+// $value = $coordsDom->nodeValue;
+// echo "===> name: ".$name. ", Value: ".$value."<br>";
+
+ foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+ list($x,$y,$z) = explode(',',$pointCoords);
+ $this->addPoint($x, $y, $cnt);
+ }
+
+ $cnt++;
+ }
+
+ }
+
+ protected function addPoint ($x, $y, $i) {
+ array_push($this->lineArray[$i], array("x" => $x, "y" => $y));
+ }
+
+ public function toGeoJSON () {
+ $numberlineArray = count($this->lineArray);
+ $str = "";
+ if ($numberlineArray > 0) {
+ $str .= "{\"type\": \"MultiLineString\", \"coordinates\":[";
+
+ for ($cnt =0; $cnt < $numberlineArray; $cnt++){
+ if ($cnt > 0) {
+ $str .= ",";
+ }
+ $str .="[";
+
+ for ($i=0; $i < count($this->lineArray[$cnt]); $i++) {
+ if ($i > 0) {
+ $str .= ",";
+ }
+ $str .= "[".$this->lineArray[$cnt][$i]["x"].",".$this->lineArray[$cnt][$i]["y"]."]";
+ }
+ $str .="]";
+ }
+ $str .= "]}";
+
+ }
+ else {
+ $e = new mb_exception("GMLMultiLine: toGeoJSON: this multiLine is null.");
+ }
+ return $str;
+ }
+}
+
+class GMLMultiPolygon {
+
+ var $polygonArray = array();
+ var $innerRingArray = array();
+
+ public function __construct() {
+
+ }
+
+ protected function addPointToRing ($i, $j, $x, $y) {
+ if (count($this->innerRingArray[$i]) <= $j) {
+ array_push($this->innerRingArray[$i], array());
+ }
+ array_push($this->innerRingArray[$i][$j], array("x" => $x, "y" => $y));
+ }
+
+
+ public function parseMultiPolygon ($domNode) {
+// echo $domNode->nodeName."<br>";
+ $simpleXMLNode = simplexml_import_dom($domNode);
+
+ $simpleXMLNode->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
+
+ $allPolygons = $simpleXMLNode->xpath("gml:polygonMember/gml:Polygon");
+
+ $cnt=0;
+ foreach ($allPolygons as $polygon) {
+ $allCoords = $polygon->xpath("gml:outerBoundaryIs/gml:LinearRing/gml:coordinates");
+
+ $this->polygonArray[$cnt] = array();
+ foreach ($allCoords as $Coords) {
+
+ $coordsDom = dom_import_simplexml($Coords);
+
+ foreach (explode(' ',$coordsDom->nodeValue) as $pointCoords) {
+ list($x,$y,$z) = explode(',',$pointCoords);
+ $this->addPoint($x, $y, $cnt);
+ }
+ }
+
+ $this->innerRingArray[$cnt] = array();
+ $innerRingNodeArray = $polygon->xpath("gml:innerBoundaryIs");
+ if ($innerRingNodeArray) {
+ $ringCount = 0;
+ foreach ($innerRingNodeArray as $ringNode) {
+ $currentRingNode = $ringNode->xpath("gml:LinearRing");
+ foreach ($currentRingNode as $node) {
+ $coordinates = $node->xpath("gml:coordinates");
+ foreach ($coordinates as $coordinate) {
+ $coordsDom = dom_import_simplexml($coordinate);
+
+ foreach(explode(' ',$coordsDom->nodeValue) as $pointCoords){
+
+ list($x,$y,$z) = explode(',',$pointCoords);
+ $this->addPointToRing($cnt, $ringCount, $x, $y);
+ }
+ }
+ $ringCount++;
+
+ }
+ }
+ }
+ $cnt++;
+ new mb_exception("create multipolygon " . serialize($this->innerRingArray));
+ }
+ }
+
+ protected function addPoint ($x, $y, $i) {
+
+ array_push($this->polygonArray[$i], array("x" => $x, "y" => $y));
+ }
+
+ public function toGeoJSON () {
+ $numberPolygonArray = count($this->polygonArray);
+ $str = "";
+ if ($numberPolygonArray > 0) {
+ $str .= "{\"type\": \"MultiPolygon\", \"coordinates\":[";
+
+ for ($cnt =0; $cnt < $numberPolygonArray; $cnt++){
+ if ($cnt > 0) {
+ $str .= ",";
+ }
+ $str .= "[";
+
+ $str .= "[";
+ for ($i=0; $i < count($this->polygonArray[$cnt]); $i++) {
+ if ($i > 0) {
+ $str .= ",";
+ }
+ $str .= "[".$this->polygonArray[$cnt][$i]["x"].",".$this->polygonArray[$cnt][$i]["y"]."]";
+ }
+ $str .= "]";
+
+ for ($i=0; $i < count($this->innerRingArray[$cnt]); $i++) {
+ $str .= ",[";
+ for ($j=0; $j < count($this->innerRingArray[$cnt][$i]); $j++) {
+ if ($j > 0) {
+ $str .= ",";
+ }
+ $str .= "[".$this->innerRingArray[$cnt][$i][$j]["x"].",".$this->innerRingArray[$cnt][$i][$j]["y"]."]";
+ }
+ $str .= "]";
+ }
+ $str .= "]";
+ }
+ $str .= "]}";
+
+ }
+ else {
+ $e = new mb_exception("GMLMultiPolygon: toGeoJSON: this multiLine is null.");
+ }
+ return $str;
+ }
+}
+?>
Added: branches/3_dev/core/lib/class_point.php
===================================================================
--- branches/3_dev/core/lib/class_point.php (rev 0)
+++ branches/3_dev/core/lib/class_point.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,202 @@
+<?php
+# $Id: class_point.php 3402 2009-01-05 10:30:08Z christoph $
+# http://www.mapbender.org/index.php/
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+
+/**
+ * A Mapbender_point is a 2- or 3-dimensional point with an EPSG.
+ */
+class Mapbender_point {
+ var $x;
+ var $y;
+ var $z;
+ var $epsg;
+
+ /**
+ * @constructor
+ */
+ function __construct() {
+ if (func_num_args() == 4) {
+ $x = func_get_arg(0);
+ $y = func_get_arg(1);
+ $z = func_get_arg(2);
+ $epsg = func_get_arg(3);
+ }
+ else if (func_num_args() == 3) {
+ $x = func_get_arg(0);
+ $y = func_get_arg(1);
+ $z = false;
+ $epsg = func_get_arg(2);
+ }
+ else {
+ return;
+ }
+
+ if (!isset($x) || !isset($y) || !isset($epsg)) {
+ $e = new mb_exception("Mapbender_point: constructor: some parameters are not set (set (x: ".$x.", y: ".$y.", z: ".$z.", epsg:".$epsg.")!");
+ }
+ $this->x = $x;
+ $this->y = $y;
+ $this->z = $z;
+ $this->epsg = $epsg;
+ }
+
+ /**
+ * computes a new point with the minimal coordinates of this point and $point
+ */
+ static function min ($point1, $point2) {
+ if ($point1->epsg == $point2->epsg) {
+ if ($point1->isWestOf($point2)) {
+ $minx = $point1->x;
+ }
+ else {
+ $minx = $point2->x;
+ }
+ if ($point1->isSouthOf($point2)) {
+ $miny = $point1->y;
+ }
+ else {
+ $miny = $point2->y;
+ }
+ return new Mapbender_point($minx, $miny, $point1->epsg);
+ }
+ else {
+ $e = new mb_exception("Mapbender_point: cannot process min with different EPSG codes");
+ }
+ }
+
+ /**
+ * computes a new point with the maximal coordinates of this point and $point
+ */
+ static function max ($point1, $point2) {
+ if ($point1->epsg == $point2->epsg) {
+ if ($point1->isWestOf($point2)) {
+ $maxx = $point2->x;
+ }
+ else {
+ $maxx = $point1->x;
+ }
+ if ($point1->isSouthOf($point2)) {
+ $maxy = $point2->y;
+ }
+ else {
+ $maxy = $point1->y;
+ }
+ return new Mapbender_point($maxx, $maxy, $point1->epsg);
+ }
+ else {
+ $e = new mb_exception("Mapbender_point: cannot process min with different EPSG codes");
+ }
+ }
+
+ function isWestOf($point) {
+ if ($this->x < $point->x) {
+ return true;
+ }
+ }
+
+ function isSouthOf($point) {
+ if ($this->y < $point->y) {
+ return true;
+ }
+ }
+
+ /**
+ * Addition
+ *
+ * @param anotherPoint another Mapbender_point
+ */
+ function plus ($anotherPoint) {
+ return new Mapbender_point($this->x + $anotherPoint->x, $this->y + $anotherPoint->y, $this->epsg);
+ }
+
+ /**
+ * Subtraction
+ *
+ * @param anotherPoint another Mapbender_point
+ */
+ function minus ($anotherPoint) {
+ return $this->plus($anotherPoint->times(-1));
+ }
+
+ /**
+ * Scalar multiplication
+ *
+ * @param aFloat a floating point number
+ */
+ function times ($aFloat) {
+ return new Mapbender_point($this->x * $aFloat, $this->y * $aFloat, $this->epsg);
+ }
+
+ /**
+ * transforms this point to another EPSG
+ *
+ * @param {Integer} toEpsg the coordinates are transformed to this EPSG code.
+ */
+ function transform($toEpsg) {
+ if(SYS_DBTYPE=='pgsql'){
+ $currentEpsg = preg_replace("/EPSG:/", "", $this->epsg);
+ $targetEpsg = preg_replace("/EPSG:/", "", $toEpsg);
+ $sql = "SELECT X(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as x, ";
+ $sql .= "Y(transform(GeometryFromText('POINT(".$this->x." ".$this->y.")',".$currentEpsg."),".$targetEpsg.")) as y, ";
+ if (isset($this->z)) {
+ $sql .= "Z(transform(GeometryFromText('POINT(".$this->x." ".$this->y." ".$this->z.")',".$currentEpsg."),".$targetEpsg.")) as z";
+ }
+ $res = db_query($sql);
+ if (isset($this->z)) {
+ $point = new Mapbender_point(db_result($res,0,"x"), db_result($res,0,"y"), db_result($res,0,"z"), $toEpsg);
+ }
+ else {
+ $point = new Mapbender_point(db_result($res,0,"x"), db_result($res,0,"y"), $toEpsg);
+ }
+ $this->x = $point->x;
+ $this->y = $point->y;
+ $this->z = $point->z;
+ $this->epsg = $point->epsg;
+ }
+ else {
+ $e = new mb_exception("transformCoordinates needs PostgreSQL");
+ }
+ }
+
+ function toHtml () {
+ $str = "";
+
+ $xArray = explode(".", strval($this->x));
+ $str .= $xArray[0] . "°";
+ if ($xArray[1]) {
+ $str .= $xArray[1] . "'";
+ }
+ $str .= " O / ";
+
+ $yArray = explode(".", strval($this->y));
+ $str .= $yArray[0] . "°";
+ if ($yArray[1]) {
+ $str .= $yArray[1] . "'";
+ }
+ $str .= " N";
+ return $str;
+
+ }
+
+ function __toString() {
+ return (string) "(" . $this->x . "," . $this->y . "," . $this->z . "," . $this->epsg . ")";
+ }
+}
+?>
Added: branches/3_dev/core/lib/class_rss.php
===================================================================
--- branches/3_dev/core/lib/class_rss.php (rev 0)
+++ branches/3_dev/core/lib/class_rss.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,181 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/class_Administration.php";
+require_once dirname(__FILE__) . "/class_rss_item.php";
+
+/**
+ * Creates an RSS Feed.
+ */
+class Rss {
+ var $filename;
+
+ var $channel_url;
+ var $channel_title;
+ var $channel_description;
+ var $channel_lang;
+ var $channel_copyright;
+ var $channel_date;
+ var $channel_creator;
+ var $channel_subject;
+ var $image_url;
+ protected $items = array();
+ protected $nritems;
+
+ const MAX_ENTRIES = 10;
+
+ protected function createItem () {
+ return new RssItem();
+ }
+
+ public function append () {
+ if (func_num_args() === 0) {
+ $item = $this->createItem();
+ }
+ else {
+ $item = func_get_arg(0);
+ }
+ $this->items[]= $item;
+ $this->nritems++;
+ return $item;
+ }
+
+ public function saveAsFile() {
+ if (func_num_args() === 1) {
+ $pathAndFilename = func_get_arg(0);
+ }
+ else {
+ if ($this->filename) {
+ $pathAndFilename = $this->filename;
+ }
+ else {
+ new mb_exception(__FILE__ .
+ ": saveAsFile(): must specify a filename!");
+ return false;
+ }
+ }
+ return administration::saveFile($pathAndFilename, $this->__toString());
+ }
+
+ public function __construct() {
+ $this->nritems=0;
+ $this->channel_url=LOGIN;
+ $this->channel_title="Mapbender GeoRSS";
+ $this->channel_description="New and updated WMS";
+ $this->channel_lang='';
+ $this->channel_copyright='';
+ $this->channel_date='';
+ $this->channel_creator='';
+ $this->channel_subject='';
+ $this->image_url='';
+ }
+
+ public function setTitle ($title) {
+ $this->channel_title=$title;
+ }
+
+ public function setDescription ($description) {
+ $this->channel_description=$description;
+ }
+
+ public function setUrl ($url) {
+ $this->channel_url=$url;
+ }
+
+ public function setChannel($url, $title, $description, $lang, $copyright, $creator, $subject) {
+ $this->channel_url=$url;
+ $this->channel_title=$title;
+ $this->channel_description=$description;
+ $this->channel_lang=$lang;
+ $this->channel_copyright=$copyright;
+ $this->channel_date=date("Y-m-d").'T'.date("H:i:s").'+01:00';
+ $this->channel_creator=$creator;
+ $this->channel_subject=$subject;
+ }
+
+ public function setImage($url) {
+ $this->image_url=$url;
+ }
+
+ public function setItem($rssItem) {
+ if (is_a($rssItem, "RssItem")) {
+ $this->items[]= $rssItem;
+ $this->nritems++;
+ return true;
+ }
+ new mb_exception(__FILE__ .
+ ": setItem(): parameter is not an RSS item!");
+ }
+
+ public function getItem ($index) {
+ if (!is_numeric($index)) {
+ return null;
+ }
+ $i = intval($index);
+ if ($i >= 0 && $i < count($this->items)) {
+ return $this->items[$i];
+ }
+ return null;
+ }
+
+ public function __toString () {
+ $output = '<?xml version="1.0" encoding="' . CHARSET . '"?>'."\n";
+ $output .= '<rss ' . $this->getNamespaceString() . ' version="2.0">'."\n";
+// $output .= '<rdf:RDF ' . $this->getNamespaceString() . '>'."\n";
+// $output .= '<channel rdf:about="'.htmlentities($this->channel_url, ENT_QUOTES, CHARSET) .'">'."\n";
+ $output .= '<channel>'."\n";
+ $output .= '<title>'.$this->channel_title.'</title>'."\n";
+ $output .= '<link>'.htmlentities(
+ $this->channel_url,
+ ENT_QUOTES,
+ CHARSET
+ ).'</link>'."\n";
+ $output .= '<description>'.$this->channel_description.'</description>'."\n";
+# $output .= '<dc:language>'.$this->channel_lang.'</dc:language>'."\n";
+# $output .= '<dc:rights>'.$this->channel_copyright.'</dc:rights>'."\n";
+# $output .= '<dc:date>'.$this->channel_date.'</dc:date>'."\n";
+# $output .= '<dc:creator>'.$this->channel_creator.'</dc:creator>'."\n";
+# $output .= '<dc:subject>'.$this->channel_subject.'</dc:subject>'."\n";
+
+# $output .= '<items>'."\n";
+# $output .= '<rdf:Seq>';
+# for($k=0; $k<$this->nritems; $k++) {
+# $output .= '<rdf:li rdf:resource="'.
+# htmlentities(
+# $this->items[$k]->getUrl(),
+# ENT_QUOTES,
+# CHARSET
+# )
+# .'"/>'."\n";
+# };
+# $output .= '</rdf:Seq>'."\n";
+# $output .= '</items>'."\n";
+# $output .= '<image rdf:resource="'.$this->image_url.'"/>'."\n";
+ for($k=0; $k<$this->nritems; $k++) {
+ $output .= $this->items[$k];
+ };
+ $output .= '</channel>'."\n";
+// $output .= '</rdf:RDF>'."\n";
+ $output .= '</rss>'."\n";
+ return $output;
+ }
+
+ protected function getNamespaceString () {
+ return "";
+# return 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ' .
+# 'xmlns="http://purl.org/rss/1.0/" ' .
+# 'xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ' .
+# 'xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" ' .
+# 'xmlns:dc="http://purl.org/dc/elements/1.1/" ' .
+# 'xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" ' .
+# 'xmlns:admin="http://webns.net/mvcb/" ' .
+# 'xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0"';
+ }
+}
+
+?>
Added: branches/3_dev/core/lib/class_rss_factory.php
===================================================================
--- branches/3_dev/core/lib/class_rss_factory.php (rev 0)
+++ branches/3_dev/core/lib/class_rss_factory.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,131 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once dirname(__FILE__) . "/../../core/globalSettings.php";
+require_once dirname(__FILE__) . "/class_rss.php";
+
+class RssFactory {
+
+ protected function createRss () {
+ $rss = new Rss();
+ return $rss;
+ }
+
+ protected function createRssItem () {
+ $rssItem = new RssItem();
+ return $rssItem;
+ }
+
+ public function loadOrCreate ($pathAndFilename) {
+ $rss = $this->createFromUrl($pathAndFilename);
+ if (is_null($rss)) {
+ $rss = $this->createAt($pathAndFilename);
+ if (is_null($rss)) {
+ return null;
+ }
+ }
+ return $rss;
+ }
+
+ public function createAt ($pathAndFilename) {
+ $rss = $this->createRss();
+ if ($rss->saveAsFile($pathAndFilename)) {
+ $rss->filename = $pathAndFilename;
+ return $rss;
+ };
+ return null;
+ }
+
+ public function createFromUrl ($url) {
+ $rss = $this->parseDocument($url, $this->createRss());
+ if (is_null($rss)) {
+ return null;
+ }
+ $rss->filename = $url;
+ return $this->parseItems($url, $rss);
+ }
+
+ protected function parseDocument ($url, $rss) {
+ $domxpath = $this->createDomXpathFromUrl($url, $rss);
+ if (is_null($domxpath)) {
+ return null;
+ }
+
+ $nodeList = $domxpath->query("/rss/channel/title");
+ if ($nodeList->length === 1) {
+ $rss->channel_title = trim($nodeList->item(0)->nodeValue);
+ }
+ else {
+ new mb_warning(__FILE__ . ": load(): Could not find title in RSS feed.");
+ }
+
+ $nodeList = $domxpath->query("/rss/channel/description");
+ if ($nodeList->length === 1) {
+ $rss->channel_description = trim($nodeList->item(0)->nodeValue);
+ }
+ else {
+ new mb_warning(__FILE__ . ": load(): Could not find description in RSS feed.");
+ }
+
+ $nodeList = $domxpath->query("/rss/channel/link");
+ if ($nodeList->length === 1) {
+ $rss->channel_url = trim($nodeList->item(0)->nodeValue);
+ }
+ else {
+ new mb_warning(__FILE__ . ": load(): Could not find url in RSS feed.");
+ }
+ return $rss;
+ }
+
+ protected function createDomXpathFromUrl ($url) {
+ $dom = new DOMDocument();
+ $dom->preserveWhitespace = false;
+ $success = $dom->load($url);
+ if (!$success) {
+ new mb_exception(__FILE__ . ": load(): Could not load " . $url);
+ return null;
+ }
+
+ return new DOMXPath($dom);
+ }
+
+ protected function parseItems ($url, $rss) {
+ $domxpath = $this->createDomXpathFromUrl($url, $rss);
+ if (is_null($domxpath)) {
+ return null;
+ }
+
+ $nodeList = $domxpath->query("/rss/channel/item");
+ foreach ($nodeList as $node) {
+ $item = $this->createRssItem();
+ $item = $this->parseItem($node, $item);
+ $rss->append($item);
+ }
+ return $rss;
+ }
+
+ protected function parseItem ($node, $item) {
+ foreach ($node->childNodes as $childNode) {
+ switch ($childNode->tagName) {
+ case "title":
+ $item->setTitle(trim($childNode->nodeValue));
+ break;
+
+ case "description":
+ $item->setDescription(trim($childNode->nodeValue));
+ break;
+
+ case "link":
+ $item->setUrl(trim($childNode->nodeValue));
+ break;
+ }
+ }
+ return $item;
+ }
+}
+
+?>
Added: branches/3_dev/core/lib/class_rss_item.php
===================================================================
--- branches/3_dev/core/lib/class_rss_item.php (rev 0)
+++ branches/3_dev/core/lib/class_rss_item.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,50 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_rss.php");
+
+class RssItem {
+ protected $title;
+ protected $description;
+ protected $url;
+
+ public function __construct () {
+ }
+
+ public function setUrl ($url) {
+ $this->url = $url;
+ }
+
+ public function getUrl () {
+ return $this->url;
+ }
+
+ public function setTitle ($title) {
+ $this->title = $title;
+ }
+
+ public function setDescription ($description) {
+ $this->description = $description;
+ }
+
+ public function __toString () {
+ return '<item>'."\n" .
+ $this->getItemString() . '</item>'."\n";
+# return '<item rdf:about="' . $this->url . '">'."\n" .
+# $this->getItemString() . '</item>'."\n";
+ }
+
+ protected function getItemString () {
+ return '<title>' . $this->title . '</title>' . "\n" .
+ '<link>' . htmlentities($this->url, ENT_QUOTES, CHARSET) . '</link>' . "\n" .
+ '<description>' . $this->description . '</description>' . "\n";
+// '<feedburner:origLink>' . $this->url . '</feedburner:origLink>' .
+// "\n";
+ }
+}
+?>
Added: branches/3_dev/core/lib/initWms.php
===================================================================
--- branches/3_dev/core/lib/initWms.php (rev 0)
+++ branches/3_dev/core/lib/initWms.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,18 @@
+<?php
+//
+// Load WMS
+//
+require_once(dirname(__FILE__)."/../validateSession.php");
+require_once(dirname(__FILE__)."/class_Wms.php");
+require_once(dirname(__FILE__)."/class_Administration.php");
+
+$wmsArray = wms::selectMyWmsByApplication($gui_id);
+
+for ($i = 0; $i < count($wmsArray); $i++) {
+ $currentWms = $wmsArray[$i];
+
+ $output = $currentWms->createJsObjFromWMS_();
+ echo administration::convertOutgoingString($output);
+ unset($output);
+}
+?>
Added: branches/3_dev/core/lib/mod_map_messages.php
===================================================================
--- branches/3_dev/core/lib/mod_map_messages.php (rev 0)
+++ branches/3_dev/core/lib/mod_map_messages.php 2010-05-09 16:02:50 UTC (rev 6120)
@@ -0,0 +1,37 @@
+<?php
+#$Id: mod_insertWmcIntoDb.php 507 2006-11-20 10:55:57Z christoph $
+#$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_insertWmcIntoDb.php,v 1.19 2006/03/09 14:02:42 uli_rothstein Exp $
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+require_once(dirname(__FILE__)."/../classes/class_json.php");
+
+$e = new mb_notice("locale: " . Mapbender::session()->get("mb_locale") . "; lang: " . Mapbender::session()->get("mb_lang"));
+$e = new mb_notice(setlocale(LC_ALL, Mapbender::session()->get("mb_locale")));
+
+//
+// Messages
+//
+$msg_obj = array();
+$msg_obj["srsNotSupported"] = _mb("The following WMS do not support the current SRS");
+
+$json = new Mapbender_JSON();
+$output = $json->encode($msg_obj);
+
+header("Content-type:application/x-json; charset=utf-8");
+echo $output;
+?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list