From 0ba1cdec9edfbe4f4efa50b8f054186041f4ca6b Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Wed, 27 Jan 2016 01:53:28 +0000 Subject: [PATCH] Inclusão do formato JSON na listagem dos dados dos menus --- admin/dicionario/menup.js | 5 +++++ admin/menu.html | 7 ++++++- admin/php/parsemapfile.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------ admin/php/xml.php | 43 +++++++++++++++++++++++++++++++++---------- admin/rssgrupos.php | 8 ++++++-- admin/rsssubgrupos.php | 8 ++++++-- admin/rsstemas.php | 8 ++++++-- 7 files changed, 192 insertions(+), 53 deletions(-) diff --git a/admin/dicionario/menup.js b/admin/dicionario/menup.js index ca02e3f..2664b47 100755 --- a/admin/dicionario/menup.js +++ b/admin/dicionario/menup.js @@ -136,6 +136,11 @@ i3GEOadmin.menup.dicionario = { en : "", es : "" } ], + 'rssArvoreJson' : [ { + pt : "Ver JSON com os grupos, subgrupos e temas", + en : "", + es : "" + } ], 'rssComentarios' : [ { pt : "Ver RSS com os comentários sobre os temas", en : "", diff --git a/admin/menu.html b/admin/menu.html index d7d2193..39f1082 100644 --- a/admin/menu.html +++ b/admin/menu.html @@ -177,11 +177,16 @@ enableHighlight: false, },{ - html: ""+$trad("rssArvore",i3GEOadmin.menup.dicionario)+"", + html: ""+$trad("rssArvore",i3GEOadmin.menup.dicionario)+"", type: "html", enableHighlight: false, },{ + html: ""+$trad("rssArvoreJson",i3GEOadmin.menup.dicionario)+"", + type: "html", + enableHighlight: false, + + },{ html: ""+$trad("rssComentarios",i3GEOadmin.menup.dicionario)+"", type: "html", enableHighlight: false, diff --git a/admin/php/parsemapfile.php b/admin/php/parsemapfile.php index b61d321..5bdc2f5 100644 --- a/admin/php/parsemapfile.php +++ b/admin/php/parsemapfile.php @@ -85,16 +85,20 @@ if($indevidos == true){ } // $mapa = ms_newMapObj($mapfile); -if(!isset($tipoparse) || $tipoparse=="") -{mapfile();exit;} +if(!isset($tipoparse) || $tipoparse==""){ + mapfile($_GET["output"]); + exit; +} if($tipoparse == "legenda") { $tipoLegenda = tipoLegenda($layername); - if($tipoLegenda == "simples") - {legendaSimples($layername);} - if($tipoLegenda == "valorunico") - legendaValorUnico($layername); + if($tipoLegenda == "simples"){ + legendaSimples($layername); + } + if($tipoLegenda == "valorunico"){ + legendaValorUnico($layername); + } } // //verifica o tipo de legenda @@ -279,7 +283,7 @@ function legendaSimples($layername) // //gera xml com parâmetros do mapfile // -function mapfile() +function mapfile($output="xml") { global $codigoLayer,$mapfile,$mapa,$objcontype,$objlayertypes,$forcawms,$postgis_mapa,$bloqueiaStringConexao; $layers = $mapa->getalllayernames(); @@ -288,11 +292,15 @@ function mapfile() $xml .= "\n\n"; $xml .= "".implode(",",$objcontype)."\n"; $xml .= "".implode(",",$objlayertypes)."\n"; + $json = array( + "tiposconexao"=>implode(",",$objcontype), + "tiposlayer"=>implode(",",$objlayertypes), + ); //verifica se tem grupos $nlayers = array(); - foreach ($layers as $layer) + foreach ($layers as $layerName) { - $layer = $mapa->getlayerbyname($layer); + $layer = $mapa->getlayerbyname($layerName); if($objcontype[$layer->connectiontype] != MS_WMS ) { if($layer->group == "") @@ -305,16 +313,19 @@ function mapfile() $layers = $nlayers; } } - foreach ($layers as $layer) + foreach ($layers as $layerName) { $xml .= "\n\n"; - $layer = $mapa->getlayerbyname($layer); + $layer = $mapa->getlayerbyname($layerName); $xml .= "".$layer->getmetadata('tema')."\n"; + $json["layer"] = array(); $d = $layer->data; - if (@$layer->open() == MS_SUCCESS) - {$colunas = implode(",",$layer->getItems());} - else - {$colunas = "*";} + if (@$layer->open() == MS_SUCCESS){ + $colunas = implode(",",$layer->getItems()); + } + else{ + $colunas = "*"; + } $ct = $objcontype[$layer->connectiontype]; $tagLegenda = "parsemapfile.php?id=".$codigoLayer."&layername=".$layer->name."&tipoparse=legenda"; $nomeLayer = $layer->name; @@ -323,9 +334,13 @@ function mapfile() $ct = "MS_WMS"; $d = "http://".$_SERVER['HTTP_HOST'].str_replace("/admin/php/parsemapfile.php","",$_SERVER['PHP_SELF'])."/ogc.php?tema=".$codigoLayer; $xml .= "1.1.1"; - $xml .= "EPSG:4618"; + $json["layer"]["version"] = "1.1.1"; + $xml .= "EPSG:4326"; + $json["layer"]["srs"] = "EPSG:4326"; $xml .= "image/png"; + $json["layer"]["format"] = "image/png"; $xml .= ""; + $json["layer"]["style"] = "default"; $tagLegenda = ""; } else if($ct == "MS_WMS") @@ -349,18 +364,27 @@ function mapfile() if($s == "") {$s = "default";} $xml .= "$v"; + $json["layer"]["version"] = $v; $xml .= "$e"; + $json["layer"]["srs"] = $e; $xml .= "image/png"; + $json["layer"]["format"] = "image/png"; $xml .= ""; + $json["layer"]["style"] = $s; $tagLegenda = ""; } - $xml .= "$tagLegenda"; + $xml .= ""; + $json["layer"]["geraxmllegenda"] = $tagLegenda; $xml .= "".$ct."\n"; + $json["layer"]["connectiontype"] = $ct; $xml .= "$d\n"; + $json["layer"]["data"] = $d; $xml .= "$nomeLayer\n"; + $json["layer"]["name"] = $nomeLayer; if($ct != "MS_WMS") { $xml .= "\n"; + $json["layer"]["connection"] = array(); $con = $layer->connection; if (($con == " ") || ($con == "") || (in_array($con,array_keys($postgis_mapa)))) { @@ -370,18 +394,32 @@ function mapfile() {$con = $postgis_mapa[$con];} } if($bloqueiaStringConexao == true){ - $xml .= "bloqueado (veja i3geo/admin/php/parsemapfile)\n"; - $xml .= "\n"; - $xml .= "\n"; - $xml .= "\n"; + $xml .= "bloqueado (veja i3geo/admin/php/parsemapfile)\n"; + $json["layer"]["connection"]["user"] = "bloqueado (veja i3geo/admin/php/parsemapfile)"; + $xml .= "\n"; + $json["layer"]["connection"]["password"] = ""; + $xml .= "\n"; + $json["layer"]["connection"]["dbname"] = ""; + $xml .= "\n"; + $json["layer"]["connection"]["host"] = ""; $xml .= "\n"; + $json["layer"]["connection"]["port"] = ""; } else{ $xml .= "".preg_replace('/.*user\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n"; + $json["layer"]["connection"]["user"] = preg_replace('/.*user\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); + $xml .= "".preg_replace('/.*password\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n"; + $json["layer"]["connection"]["password"] = preg_replace('/.*password\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); + $xml .= "".preg_replace('/.*dbname\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n"; + $json["layer"]["connection"]["dbname"] = preg_replace('/.*dbname\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); + $xml .= "".preg_replace('/.*host\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n"; + $json["layer"]["connection"]["host"] = preg_replace('/.*host\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); + $xml .= "".preg_replace('/.*port\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."\n"; + $json["layer"]["connection"]["port"] = preg_replace('/.*port\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); } $xml .= "\n"; $d = explode("(",$d); @@ -390,7 +428,9 @@ function mapfile() $dstring = str_replace("the_geom","",$dstring); $dstring = str_replace("*",$colunas,$dstring); $xml .= "$colunas"; + $json["layer"]["colunas"] = $colunas; $xml .= "\n"; + $json["layer"]["select"] = $dstring; $string = preg_replace('/.*from\s*(.+).*/i', '\1', $d[0]); $s = explode("WHERE",$string); if(count($s) == 1) @@ -402,18 +442,35 @@ function mapfile() $xml .= "".$objlayertypes[$layer->type]."\n"; $xml .= "".$layer->getfilterstring()."\n"; $xml .= "$layer->filteritem\n"; - //$xml .= "".$layer->labelangleitem."\n"; $xml .= "$layer->labelitem\n"; $xml .= "$layer->labelmaxscaledenom\n"; $xml .= "$layer->labelminscaledenom\n"; $xml .= "\n"; + + $json["layer"]["esquema"] = $esquemaTabela[0]; + $json["layer"]["tabela"] = $esquemaTabela[1]; + $json["layer"]["where"] = $s[1]; + $json["layer"]["type"] = $objlayertypes[$layer->type]; + $json["layer"]["filter"] = $layer->getfilterstring(); + $json["layer"]["filteritem"] = $layer->filteritem; + $json["layer"]["labelitem"] = $layer->labelitem; + $json["layer"]["labelmaxscale"] = $layer->labelmaxscaledenom; + $json["layer"]["labelminscale"] = $layer->labelminscaledenom; + $json["layer"]["labelsizeitem"] = ""; } $xml .= "$layer->group\n"; $xml .= "$layer->maxscaledenom\n"; $xml .= "$layer->minscaledenom\n"; $xml .= "".$layer->offsite->red.",".$layer->offsite->green.",".$layer->offsite->blue."\n"; $xml .= "$layer->opacity\n"; - if($ct != "MS_WMS") + + $json["layer"]["group"] = $layer->group; + $json["layer"]["maxscale"] = $layer->maxscaledenom; + $json["layer"]["minscale"] = $layer->minscaledenom; + $json["layer"]["offsite"] = $layer->offsite->red.",".$layer->offsite->green.",".$layer->offsite->blue; + $json["layer"]["opacity"] = $layer->opacity; + + if($ct != "xMS_WMS") { $xml .= "$layer->symbolscaledenom\n"; $xml .= "$layer->tileindex\n"; @@ -423,18 +480,33 @@ function mapfile() $xml .= "$layer->sizeunits\n"; $xml .= "".$layer->getProjection()."\n"; $xml .= "\n"; - $xml = pegaClasses($xml); + $xml .= pegaClasses($layer,"xml"); $xml .= "\n"; + + $json["layer"]["symbolscale"] = $layer->symbolscaledenom; + $json["layer"]["tileindex"] = $layer->tileindex; + $json["layer"]["tileitem"] = $layer->tileitem; + $json["layer"]["tolerance"] = $layer->tolerance; + $json["layer"]["toleranceunits"] = $layer->toleranceunits; + $json["layer"]["sizeunits"] = $layer->sizeunits; + $json["layer"]["projection"] = $layer->getProjection(); + $json["layer"]["classes"] = pegaClasses($layer,"json"); } $xml .= ""; } $xml .= "\n"; - echo header("Content-type: application/xml"); - echo $xml; + echo header("Content-type: application/".$output); + if($output=="xml"){ + echo $xml; + } + else{ + echo json_encode($json); + } } -function pegaClasses($xml) +function pegaClasses($layer,$output="xml") { - global $layer; + $xml = ""; + $json = array(); $dados = array(); $nclasses = $layer->numclasses; for($i=0;$i<$nclasses;++$i) @@ -444,20 +516,29 @@ function pegaClasses($xml) $xml .= "".mb_convert_encoding(($classe->name),"UTF-8","ISO-8859-1")."\n"; $xml .= "".$classe->getExpressionString()."\n"; $xml .= "$classe->keyimage\n"; - $xml .= "$classe->size\n"; - $xml .= "$classe->symbolname\n"; - $xml .= "$classe->type\n"; $xml .= "\n"; - $xml = pegaEstilos($xml,$classe); + $xml .= pegaEstilos($classe,$output); $xml .= "\n"; $xml .= "\n"; + + $j = array(); + $j["name"] = mb_convert_encoding(($classe->name),"UTF-8","ISO-8859-1"); + $j["expression"] = $classe->getExpressionString(); + $j["keyimage"] = $classe->keyimage; + $j["estilos"] = pegaEstilos($classe,$output); + $json[] = $j; + } + if($output == "xml"){ + return $xml; + } + else{ + return $json; } - return $xml; } -function pegaEstilos($xml,$classe) +function pegaEstilos($classe,$output = "xml") { $numestilos = $classe->numstyles; - $estilos = array(); + $json = array(); for($j=0;$j<$numestilos;++$j) { $xml .= "\n"; @@ -468,7 +549,20 @@ function pegaEstilos($xml,$classe) $xml .= "".$estilo->backgroundcolor->red.",".$estilo->backgroundcolor->green.",".$estilo->backgroundcolor->blue."\n"; $xml .= "".$estilo->outlinecolor->red.",".$estilo->outlinecolor->green.",".$estilo->outlinecolor->blue."\n"; $xml .= "\n"; + + $e = array(); + $e["symbolname"] = $estilo->symbolname; + $e["color"] = $estilo->color->red.",".$estilo->color->green.",".$estilo->color->blue; + $e["size"] = $estilo->size; + $e["backgroundcolor"] = $estilo->backgroundcolor->red.",".$estilo->backgroundcolor->green.",".$estilo->backgroundcolor->blue; + $e["outlinecolor"] = $estilo->outlinecolor->red.",".$estilo->outlinecolor->green.",".$estilo->outlinecolor->blue; + $json[] = $e; + } + if($output == "xml"){ + return $xml; + } + else{ + return $json; } - return $xml; } ?> \ No newline at end of file diff --git a/admin/php/xml.php b/admin/php/xml.php index 2e475d3..f6cdb43 100644 --- a/admin/php/xml.php +++ b/admin/php/xml.php @@ -142,7 +142,7 @@ Retorno: RSS */ -function geraRSStemas($locaplic,$id_n2) +function geraRSStemas($locaplic,$id_n2,$output="xml") { global $esquemaadmin; $sql = " @@ -151,7 +151,7 @@ function geraRSStemas($locaplic,$id_n2) LEFT JOIN ".$esquemaadmin."i3geoadmin_temas ON i3geoadmin_temas.id_tema = n3.id_tema LEFT JOIN ".$esquemaadmin."i3geousr_grupotema ON n3.id_tema = i3geousr_grupotema.id_tema where i3geousr_grupotema.id_grupo is null and i3geoadmin_temas.id_tema = n3.id_tema and n3.id_n2 = '$id_n2' and n3.n3_perfil = '' and n3.publicado != 'NAO' order by nome_ws"; - return geraXmlRSS($locaplic,$sql,"Lista de temas"); + return geraXmlRSS($locaplic,$sql,"Lista de temas",$output); } /* Function: geraRSStemasRaiz @@ -196,12 +196,12 @@ Retorno: RSS */ -function geraRSSsubgrupos($locaplic,$id_n1) +function geraRSSsubgrupos($locaplic,$id_n1,$output="json") { global $esquemaadmin; $sql = "select '' as tipo_ws, n2.id_n2 as id_ws,g.nome_subgrupo as nome_ws,'' as desc_ws,'rsstemas.php?id='||n2.id_n2 as link_ws,'' as autor_ws from ".$esquemaadmin."i3geoadmin_n2 as n2,".$esquemaadmin."i3geoadmin_subgrupos as g "; $sql .= " where g.id_subgrupo = n2.id_subgrupo and n2.id_n1 = '$id_n1' and n2.n2_perfil = '' and n2.publicado != 'NAO' order by nome_ws"; - return geraXmlRSS($locaplic,$sql,"Lista de sub-grupos"); + return geraXmlRSS($locaplic,$sql,"Lista de sub-grupos",$output); } /* Function: geraRSSgrupos @@ -216,13 +216,13 @@ Retorno: RSS */ -function geraRSSgrupos($locaplic) +function geraRSSgrupos($locaplic,$output="xml") { global $esquemaadmin; $sql = "select '' as tipo_ws, n1.id_n1 as id_ws, g.nome_grupo as nome_ws,'rsstemasraiz.php?nivel=1&id='||n1.id_n1 as desc_ws,'rsssubgrupos.php?id='||n1.id_n1 as link_ws,'' as autor_ws "; $sql .= "from ".$esquemaadmin."i3geoadmin_n1 as n1,".$esquemaadmin."i3geoadmin_grupos as g "; $sql .= "where g.id_grupo = n1.id_grupo and n1.n1_perfil = '' and n1.publicado != 'NAO' group by id_ws,tipo_ws,nome_ws,desc_ws,link_ws,autor_ws order by nome_ws"; - return geraXmlRSS($locaplic,$sql,"Lista de grupos"); + return geraXmlRSS($locaplic,$sql,"Lista de grupos",$output); } /* Function: geraXmlDownload @@ -474,11 +474,13 @@ locaplic {string} - localização do i3Geo no sistema de arquivos sql {string} - SQL que será aplicado ao sistema de administração descricao {string} - descrição que será inserida no canal RSS + +output {string} - xml|json Retorno: RSS */ -function geraXmlRSS($locaplic,$sql,$descricao) +function geraXmlRSS($locaplic,$sql,$descricao,$output="xml") { global $esquemaadmin; //var_dump($_SERVER);exit; @@ -497,6 +499,12 @@ function geraXmlRSS($locaplic,$sql,$descricao) $xml .= "Gerado pelo i3Geo\n"; $xml .= "pt-br\n"; $xml .= "\n"; + $json = array( + "description"=>$descricao, + "copyright"=>"Gerado pelo i3Geo", + "language"=>"pt-br" + ); + $jsonItems = array(); $qatlas = $dbh->query($sql); foreach($qatlas as $row) { @@ -505,8 +513,9 @@ function geraXmlRSS($locaplic,$sql,$descricao) $xml .= "".entity_decode($row["nome_ws"])."\n"; $xml .= "".xmlTexto_prepara(entity_decode($row["desc_ws"]))."\n"; $link = xmlTexto_prepara($row["link_ws"]); - if(stristr($link, 'http') === FALSE) - {$link = "http://".$_SERVER["HTTP_HOST"].dirname($_SERVER["REQUEST_URI"])."/".$link;} + if(stristr($link, 'http') === FALSE){ + $link = "http://".$_SERVER["HTTP_HOST"].dirname($_SERVER["REQUEST_URI"])."/".$link; + } $xml .= "\n"; $xml .= "\n"; $xml .= "".xmlTexto_prepara($row["autor_ws"])."\n"; @@ -515,11 +524,25 @@ function geraXmlRSS($locaplic,$sql,$descricao) $xml .= "".xmlTexto_prepara($row["id_ws"])."\n"; $xml .= "".$row["tipo_ws"]."\n"; $xml .= "\n"; + $jsonItems[] = array( + "title"=>$row["nome_ws"], + "description"=>$row["desc_ws"], + "link"=>$link."&output=json", + "author"=>$row["autor_ws"], + "id"=>$row["id_ws"], + "tipo"=>$row["tipo_ws"] + ); } + $json["items"] = $jsonItems; $xml .= "\n"; $dbh = null; $dbhw = null; - return $xml; + if($output=="xml"){ + return $xml; + } + else{ + return json_encode($json); + } } function geraXmlAtlas($locaplic,$editores) { diff --git a/admin/rssgrupos.php b/admin/rssgrupos.php index 19218a5..67cd198 100644 --- a/admin/rssgrupos.php +++ b/admin/rssgrupos.php @@ -38,6 +38,10 @@ if(!isset($locaplic)){ } include_once($locaplic."/classesphp/pega_variaveis.php"); include_once($locaplic."/admin/php/xml.php"); -echo header("Content-type: application/xml"); -echo geraRSSgrupos($locaplic); +$output = "xml"; +if(strtolower($_GET["output"]) == "json" || strtolower($_POST["output"]) == "json"){ + $output = "json"; +} +echo header("Content-type: application/".$output); +echo geraRSSgrupos($locaplic,$output); ?> \ No newline at end of file diff --git a/admin/rsssubgrupos.php b/admin/rsssubgrupos.php index 3b966a5..f9eb309 100644 --- a/admin/rsssubgrupos.php +++ b/admin/rsssubgrupos.php @@ -44,6 +44,10 @@ if(!isset($locaplic)){ } include_once($locaplic."/classesphp/pega_variaveis.php"); include_once($locaplic."/admin/php/xml.php"); -echo header("Content-type: application/xml"); -echo geraRSSsubgrupos($locaplic,$id); +$output = "xml"; +if(strtolower($_GET["output"]) == "json" || strtolower($_POST["output"]) == "json"){ + $output = "json"; +} +echo header("Content-type: application/".$output); +echo geraRSSsubgrupos($locaplic,$id,$output); ?> diff --git a/admin/rsstemas.php b/admin/rsstemas.php index 5606e73..012a5d0 100644 --- a/admin/rsstemas.php +++ b/admin/rsstemas.php @@ -44,6 +44,10 @@ if(!isset($locaplic)){ } include_once($locaplic."/classesphp/pega_variaveis.php"); include_once($locaplic."/admin/php/xml.php"); -echo header("Content-type: application/xml"); -echo geraRSStemas($locaplic,$id); +$output = "xml"; +if(strtolower($_GET["output"]) == "json" || strtolower($_POST["output"]) == "json"){ + $output = "json"; +} +echo header("Content-type: application/".$output); +echo geraRSStemas($locaplic,$id,$output); ?> -- libgit2 0.21.2