Commit 0ba1cdec9edfbe4f4efa50b8f054186041f4ca6b
1 parent
2df692e0
Exists in
master
Inclusão do formato JSON na listagem dos dados dos menus
Showing
7 changed files
with
192 additions
and
53 deletions
Show diff stats
admin/dicionario/menup.js
... | ... | @@ -136,6 +136,11 @@ i3GEOadmin.menup.dicionario = { |
136 | 136 | en : "", |
137 | 137 | es : "" |
138 | 138 | } ], |
139 | + 'rssArvoreJson' : [ { | |
140 | + pt : "Ver JSON com os grupos, subgrupos e temas", | |
141 | + en : "", | |
142 | + es : "" | |
143 | + } ], | |
139 | 144 | 'rssComentarios' : [ { |
140 | 145 | pt : "Ver RSS com os comentários sobre os temas", |
141 | 146 | en : "", | ... | ... |
admin/menu.html
... | ... | @@ -177,11 +177,16 @@ |
177 | 177 | enableHighlight: false, |
178 | 178 | |
179 | 179 | },{ |
180 | - html: "<a href='rssgrupos.php' target='principal'>"+$trad("rssArvore",i3GEOadmin.menup.dicionario)+"</a>", | |
180 | + html: "<a href='rssgrupos.php?output=xml' target='principal'>"+$trad("rssArvore",i3GEOadmin.menup.dicionario)+"</a>", | |
181 | 181 | type: "html", |
182 | 182 | enableHighlight: false, |
183 | 183 | |
184 | 184 | },{ |
185 | + html: "<a href='rssgrupos.php?output=json' target='principal'>"+$trad("rssArvoreJson",i3GEOadmin.menup.dicionario)+"</a>", | |
186 | + type: "html", | |
187 | + enableHighlight: false, | |
188 | + | |
189 | + },{ | |
185 | 190 | html: "<a href='rsscomentariostemas.php' target='principal'>"+$trad("rssComentarios",i3GEOadmin.menup.dicionario)+"</a>", |
186 | 191 | type: "html", |
187 | 192 | enableHighlight: false, | ... | ... |
admin/php/parsemapfile.php
... | ... | @@ -85,16 +85,20 @@ if($indevidos == true){ |
85 | 85 | } |
86 | 86 | // |
87 | 87 | $mapa = ms_newMapObj($mapfile); |
88 | -if(!isset($tipoparse) || $tipoparse=="") | |
89 | -{mapfile();exit;} | |
88 | +if(!isset($tipoparse) || $tipoparse==""){ | |
89 | + mapfile($_GET["output"]); | |
90 | + exit; | |
91 | +} | |
90 | 92 | |
91 | 93 | if($tipoparse == "legenda") |
92 | 94 | { |
93 | 95 | $tipoLegenda = tipoLegenda($layername); |
94 | - if($tipoLegenda == "simples") | |
95 | - {legendaSimples($layername);} | |
96 | - if($tipoLegenda == "valorunico") | |
97 | - legendaValorUnico($layername); | |
96 | + if($tipoLegenda == "simples"){ | |
97 | + legendaSimples($layername); | |
98 | + } | |
99 | + if($tipoLegenda == "valorunico"){ | |
100 | + legendaValorUnico($layername); | |
101 | + } | |
98 | 102 | } |
99 | 103 | // |
100 | 104 | //verifica o tipo de legenda |
... | ... | @@ -279,7 +283,7 @@ function legendaSimples($layername) |
279 | 283 | // |
280 | 284 | //gera xml com parâmetros do mapfile |
281 | 285 | // |
282 | -function mapfile() | |
286 | +function mapfile($output="xml") | |
283 | 287 | { |
284 | 288 | global $codigoLayer,$mapfile,$mapa,$objcontype,$objlayertypes,$forcawms,$postgis_mapa,$bloqueiaStringConexao; |
285 | 289 | $layers = $mapa->getalllayernames(); |
... | ... | @@ -288,11 +292,15 @@ function mapfile() |
288 | 292 | $xml .= "\n<parsemapfile>\n"; |
289 | 293 | $xml .= "<tiposconexao>".implode(",",$objcontype)."</tiposconexao>\n"; |
290 | 294 | $xml .= "<tiposlayer>".implode(",",$objlayertypes)."</tiposlayer>\n"; |
295 | + $json = array( | |
296 | + "tiposconexao"=>implode(",",$objcontype), | |
297 | + "tiposlayer"=>implode(",",$objlayertypes), | |
298 | + ); | |
291 | 299 | //verifica se tem grupos |
292 | 300 | $nlayers = array(); |
293 | - foreach ($layers as $layer) | |
301 | + foreach ($layers as $layerName) | |
294 | 302 | { |
295 | - $layer = $mapa->getlayerbyname($layer); | |
303 | + $layer = $mapa->getlayerbyname($layerName); | |
296 | 304 | if($objcontype[$layer->connectiontype] != MS_WMS ) |
297 | 305 | { |
298 | 306 | if($layer->group == "") |
... | ... | @@ -305,16 +313,19 @@ function mapfile() |
305 | 313 | $layers = $nlayers; |
306 | 314 | } |
307 | 315 | } |
308 | - foreach ($layers as $layer) | |
316 | + foreach ($layers as $layerName) | |
309 | 317 | { |
310 | 318 | $xml .= "\n<layer>\n"; |
311 | - $layer = $mapa->getlayerbyname($layer); | |
319 | + $layer = $mapa->getlayerbyname($layerName); | |
312 | 320 | $xml .= "<titulo>".$layer->getmetadata('tema')."</titulo>\n"; |
321 | + $json["layer"] = array(); | |
313 | 322 | $d = $layer->data; |
314 | - if (@$layer->open() == MS_SUCCESS) | |
315 | - {$colunas = implode(",",$layer->getItems());} | |
316 | - else | |
317 | - {$colunas = "*";} | |
323 | + if (@$layer->open() == MS_SUCCESS){ | |
324 | + $colunas = implode(",",$layer->getItems()); | |
325 | + } | |
326 | + else{ | |
327 | + $colunas = "*"; | |
328 | + } | |
318 | 329 | $ct = $objcontype[$layer->connectiontype]; |
319 | 330 | $tagLegenda = "parsemapfile.php?id=".$codigoLayer."&layername=".$layer->name."&tipoparse=legenda"; |
320 | 331 | $nomeLayer = $layer->name; |
... | ... | @@ -323,9 +334,13 @@ function mapfile() |
323 | 334 | $ct = "MS_WMS"; |
324 | 335 | $d = "http://".$_SERVER['HTTP_HOST'].str_replace("/admin/php/parsemapfile.php","",$_SERVER['PHP_SELF'])."/ogc.php?tema=".$codigoLayer; |
325 | 336 | $xml .= "<version>1.1.1</version>"; |
326 | - $xml .= "<srs>EPSG:4618</srs>"; | |
337 | + $json["layer"]["version"] = "1.1.1"; | |
338 | + $xml .= "<srs>EPSG:4326</srs>"; | |
339 | + $json["layer"]["srs"] = "EPSG:4326"; | |
327 | 340 | $xml .= "<format>image/png</format>"; |
341 | + $json["layer"]["format"] = "image/png"; | |
328 | 342 | $xml .= "<style>default</style>"; |
343 | + $json["layer"]["style"] = "default"; | |
329 | 344 | $tagLegenda = ""; |
330 | 345 | } |
331 | 346 | else if($ct == "MS_WMS") |
... | ... | @@ -349,18 +364,27 @@ function mapfile() |
349 | 364 | if($s == "") |
350 | 365 | {$s = "default";} |
351 | 366 | $xml .= "<version>$v</version>"; |
367 | + $json["layer"]["version"] = $v; | |
352 | 368 | $xml .= "<srs>$e</srs>"; |
369 | + $json["layer"]["srs"] = $e; | |
353 | 370 | $xml .= "<format>image/png</format>"; |
371 | + $json["layer"]["format"] = "image/png"; | |
354 | 372 | $xml .= "<style>$s</style>"; |
373 | + $json["layer"]["style"] = $s; | |
355 | 374 | $tagLegenda = ""; |
356 | 375 | } |
357 | - $xml .= "<geraxmllegenda>$tagLegenda</geraxmllegenda>"; | |
376 | + $xml .= "<geraxmllegenda><![CDATA[".$tagLegenda."]]></geraxmllegenda>"; | |
377 | + $json["layer"]["geraxmllegenda"] = $tagLegenda; | |
358 | 378 | $xml .= "<connectiontype>".$ct."</connectiontype>\n"; |
379 | + $json["layer"]["connectiontype"] = $ct; | |
359 | 380 | $xml .= "<data>$d</data>\n"; |
381 | + $json["layer"]["data"] = $d; | |
360 | 382 | $xml .= "<name>$nomeLayer</name>\n"; |
383 | + $json["layer"]["name"] = $nomeLayer; | |
361 | 384 | if($ct != "MS_WMS") |
362 | 385 | { |
363 | 386 | $xml .= "<connection>\n"; |
387 | + $json["layer"]["connection"] = array(); | |
364 | 388 | $con = $layer->connection; |
365 | 389 | if (($con == " ") || ($con == "") || (in_array($con,array_keys($postgis_mapa)))) |
366 | 390 | { |
... | ... | @@ -370,18 +394,32 @@ function mapfile() |
370 | 394 | {$con = $postgis_mapa[$con];} |
371 | 395 | } |
372 | 396 | if($bloqueiaStringConexao == true){ |
373 | - $xml .= "<user>bloqueado (veja i3geo/admin/php/parsemapfile)</user>\n"; | |
374 | - $xml .= "<password></password>\n"; | |
375 | - $xml .= "<dbname></dbname>\n"; | |
376 | - $xml .= "<host></host>\n"; | |
397 | + $xml .= "<user>bloqueado (veja i3geo/admin/php/parsemapfile)</user>\n"; | |
398 | + $json["layer"]["connection"]["user"] = "bloqueado (veja i3geo/admin/php/parsemapfile)"; | |
399 | + $xml .= "<password></password>\n"; | |
400 | + $json["layer"]["connection"]["password"] = ""; | |
401 | + $xml .= "<dbname></dbname>\n"; | |
402 | + $json["layer"]["connection"]["dbname"] = ""; | |
403 | + $xml .= "<host></host>\n"; | |
404 | + $json["layer"]["connection"]["host"] = ""; | |
377 | 405 | $xml .= "<port></port>\n"; |
406 | + $json["layer"]["connection"]["port"] = ""; | |
378 | 407 | } |
379 | 408 | else{ |
380 | 409 | $xml .= "<user>".preg_replace('/.*user\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."</user>\n"; |
410 | + $json["layer"]["connection"]["user"] = preg_replace('/.*user\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); | |
411 | + | |
381 | 412 | $xml .= "<password>".preg_replace('/.*password\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."</password>\n"; |
413 | + $json["layer"]["connection"]["password"] = preg_replace('/.*password\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); | |
414 | + | |
382 | 415 | $xml .= "<dbname>".preg_replace('/.*dbname\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."</dbname>\n"; |
416 | + $json["layer"]["connection"]["dbname"] = preg_replace('/.*dbname\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); | |
417 | + | |
383 | 418 | $xml .= "<host>".preg_replace('/.*host\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."</host>\n"; |
419 | + $json["layer"]["connection"]["host"] = preg_replace('/.*host\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); | |
420 | + | |
384 | 421 | $xml .= "<port>".preg_replace('/.*port\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con)."</port>\n"; |
422 | + $json["layer"]["connection"]["port"] = preg_replace('/.*port\s*=\s*([a-zA-Z0-9_.]+).*/i', '\1', $con); | |
385 | 423 | } |
386 | 424 | $xml .= "</connection>\n"; |
387 | 425 | $d = explode("(",$d); |
... | ... | @@ -390,7 +428,9 @@ function mapfile() |
390 | 428 | $dstring = str_replace("the_geom","",$dstring); |
391 | 429 | $dstring = str_replace("*",$colunas,$dstring); |
392 | 430 | $xml .= "<colunas>$colunas</colunas>"; |
431 | + $json["layer"]["colunas"] = $colunas; | |
393 | 432 | $xml .= "<select>$dstring</select>\n"; |
433 | + $json["layer"]["select"] = $dstring; | |
394 | 434 | $string = preg_replace('/.*from\s*(.+).*/i', '\1', $d[0]); |
395 | 435 | $s = explode("WHERE",$string); |
396 | 436 | if(count($s) == 1) |
... | ... | @@ -402,18 +442,35 @@ function mapfile() |
402 | 442 | $xml .= "<type>".$objlayertypes[$layer->type]."</type>\n"; |
403 | 443 | $xml .= "<filter>".$layer->getfilterstring()."</filter>\n"; |
404 | 444 | $xml .= "<filteritem>$layer->filteritem</filteritem>\n"; |
405 | - //$xml .= "<labelangleitem>".$layer->labelangleitem."</labelangleitem>\n"; | |
406 | 445 | $xml .= "<labelitem>$layer->labelitem</labelitem>\n"; |
407 | 446 | $xml .= "<labelmaxscale>$layer->labelmaxscaledenom</labelmaxscale>\n"; |
408 | 447 | $xml .= "<labelminscale>$layer->labelminscaledenom</labelminscale>\n"; |
409 | 448 | $xml .= "<labelsizeitem></labelsizeitem>\n"; |
449 | + | |
450 | + $json["layer"]["esquema"] = $esquemaTabela[0]; | |
451 | + $json["layer"]["tabela"] = $esquemaTabela[1]; | |
452 | + $json["layer"]["where"] = $s[1]; | |
453 | + $json["layer"]["type"] = $objlayertypes[$layer->type]; | |
454 | + $json["layer"]["filter"] = $layer->getfilterstring(); | |
455 | + $json["layer"]["filteritem"] = $layer->filteritem; | |
456 | + $json["layer"]["labelitem"] = $layer->labelitem; | |
457 | + $json["layer"]["labelmaxscale"] = $layer->labelmaxscaledenom; | |
458 | + $json["layer"]["labelminscale"] = $layer->labelminscaledenom; | |
459 | + $json["layer"]["labelsizeitem"] = ""; | |
410 | 460 | } |
411 | 461 | $xml .= "<group>$layer->group</group>\n"; |
412 | 462 | $xml .= "<maxscale>$layer->maxscaledenom</maxscale>\n"; |
413 | 463 | $xml .= "<minscale>$layer->minscaledenom</minscale>\n"; |
414 | 464 | $xml .= "<offsite>".$layer->offsite->red.",".$layer->offsite->green.",".$layer->offsite->blue."</offsite>\n"; |
415 | 465 | $xml .= "<opacity>$layer->opacity</opacity>\n"; |
416 | - if($ct != "MS_WMS") | |
466 | + | |
467 | + $json["layer"]["group"] = $layer->group; | |
468 | + $json["layer"]["maxscale"] = $layer->maxscaledenom; | |
469 | + $json["layer"]["minscale"] = $layer->minscaledenom; | |
470 | + $json["layer"]["offsite"] = $layer->offsite->red.",".$layer->offsite->green.",".$layer->offsite->blue; | |
471 | + $json["layer"]["opacity"] = $layer->opacity; | |
472 | + | |
473 | + if($ct != "xMS_WMS") | |
417 | 474 | { |
418 | 475 | $xml .= "<symbolscale>$layer->symbolscaledenom</symbolscale>\n"; |
419 | 476 | $xml .= "<tileindex>$layer->tileindex</tileindex>\n"; |
... | ... | @@ -423,18 +480,33 @@ function mapfile() |
423 | 480 | $xml .= "<sizeunits>$layer->sizeunits</sizeunits>\n"; |
424 | 481 | $xml .= "<projection>".$layer->getProjection()."</projection>\n"; |
425 | 482 | $xml .= "<classes>\n"; |
426 | - $xml = pegaClasses($xml); | |
483 | + $xml .= pegaClasses($layer,"xml"); | |
427 | 484 | $xml .= "</classes>\n"; |
485 | + | |
486 | + $json["layer"]["symbolscale"] = $layer->symbolscaledenom; | |
487 | + $json["layer"]["tileindex"] = $layer->tileindex; | |
488 | + $json["layer"]["tileitem"] = $layer->tileitem; | |
489 | + $json["layer"]["tolerance"] = $layer->tolerance; | |
490 | + $json["layer"]["toleranceunits"] = $layer->toleranceunits; | |
491 | + $json["layer"]["sizeunits"] = $layer->sizeunits; | |
492 | + $json["layer"]["projection"] = $layer->getProjection(); | |
493 | + $json["layer"]["classes"] = pegaClasses($layer,"json"); | |
428 | 494 | } |
429 | 495 | $xml .= "</layer>"; |
430 | 496 | } |
431 | 497 | $xml .= "</parsemapfile>\n"; |
432 | - echo header("Content-type: application/xml"); | |
433 | - echo $xml; | |
498 | + echo header("Content-type: application/".$output); | |
499 | + if($output=="xml"){ | |
500 | + echo $xml; | |
501 | + } | |
502 | + else{ | |
503 | + echo json_encode($json); | |
504 | + } | |
434 | 505 | } |
435 | -function pegaClasses($xml) | |
506 | +function pegaClasses($layer,$output="xml") | |
436 | 507 | { |
437 | - global $layer; | |
508 | + $xml = ""; | |
509 | + $json = array(); | |
438 | 510 | $dados = array(); |
439 | 511 | $nclasses = $layer->numclasses; |
440 | 512 | for($i=0;$i<$nclasses;++$i) |
... | ... | @@ -444,20 +516,29 @@ function pegaClasses($xml) |
444 | 516 | $xml .= "<name>".mb_convert_encoding(($classe->name),"UTF-8","ISO-8859-1")."</name>\n"; |
445 | 517 | $xml .= "<expression>".$classe->getExpressionString()."</expression>\n"; |
446 | 518 | $xml .= "<keyimage>$classe->keyimage</keyimage>\n"; |
447 | - $xml .= "<size>$classe->size</size>\n"; | |
448 | - $xml .= "<symbolname>$classe->symbolname</symbolname>\n"; | |
449 | - $xml .= "<type>$classe->type</type>\n"; | |
450 | 519 | $xml .= "<estilos>\n"; |
451 | - $xml = pegaEstilos($xml,$classe); | |
520 | + $xml .= pegaEstilos($classe,$output); | |
452 | 521 | $xml .= "</estilos>\n"; |
453 | 522 | $xml .= "</classe>\n"; |
523 | + | |
524 | + $j = array(); | |
525 | + $j["name"] = mb_convert_encoding(($classe->name),"UTF-8","ISO-8859-1"); | |
526 | + $j["expression"] = $classe->getExpressionString(); | |
527 | + $j["keyimage"] = $classe->keyimage; | |
528 | + $j["estilos"] = pegaEstilos($classe,$output); | |
529 | + $json[] = $j; | |
530 | + } | |
531 | + if($output == "xml"){ | |
532 | + return $xml; | |
533 | + } | |
534 | + else{ | |
535 | + return $json; | |
454 | 536 | } |
455 | - return $xml; | |
456 | 537 | } |
457 | -function pegaEstilos($xml,$classe) | |
538 | +function pegaEstilos($classe,$output = "xml") | |
458 | 539 | { |
459 | 540 | $numestilos = $classe->numstyles; |
460 | - $estilos = array(); | |
541 | + $json = array(); | |
461 | 542 | for($j=0;$j<$numestilos;++$j) |
462 | 543 | { |
463 | 544 | $xml .= "<estilo>\n"; |
... | ... | @@ -468,7 +549,20 @@ function pegaEstilos($xml,$classe) |
468 | 549 | $xml .= "<backgroundcolor>".$estilo->backgroundcolor->red.",".$estilo->backgroundcolor->green.",".$estilo->backgroundcolor->blue."</backgroundcolor>\n"; |
469 | 550 | $xml .= "<outlinecolor>".$estilo->outlinecolor->red.",".$estilo->outlinecolor->green.",".$estilo->outlinecolor->blue."</outlinecolor>\n"; |
470 | 551 | $xml .= "</estilo>\n"; |
552 | + | |
553 | + $e = array(); | |
554 | + $e["symbolname"] = $estilo->symbolname; | |
555 | + $e["color"] = $estilo->color->red.",".$estilo->color->green.",".$estilo->color->blue; | |
556 | + $e["size"] = $estilo->size; | |
557 | + $e["backgroundcolor"] = $estilo->backgroundcolor->red.",".$estilo->backgroundcolor->green.",".$estilo->backgroundcolor->blue; | |
558 | + $e["outlinecolor"] = $estilo->outlinecolor->red.",".$estilo->outlinecolor->green.",".$estilo->outlinecolor->blue; | |
559 | + $json[] = $e; | |
560 | + } | |
561 | + if($output == "xml"){ | |
562 | + return $xml; | |
563 | + } | |
564 | + else{ | |
565 | + return $json; | |
471 | 566 | } |
472 | - return $xml; | |
473 | 567 | } |
474 | 568 | ?> |
475 | 569 | \ No newline at end of file | ... | ... |
admin/php/xml.php
... | ... | @@ -142,7 +142,7 @@ Retorno: |
142 | 142 | |
143 | 143 | RSS |
144 | 144 | */ |
145 | -function geraRSStemas($locaplic,$id_n2) | |
145 | +function geraRSStemas($locaplic,$id_n2,$output="xml") | |
146 | 146 | { |
147 | 147 | global $esquemaadmin; |
148 | 148 | $sql = " |
... | ... | @@ -151,7 +151,7 @@ function geraRSStemas($locaplic,$id_n2) |
151 | 151 | LEFT JOIN ".$esquemaadmin."i3geoadmin_temas ON i3geoadmin_temas.id_tema = n3.id_tema |
152 | 152 | LEFT JOIN ".$esquemaadmin."i3geousr_grupotema ON n3.id_tema = i3geousr_grupotema.id_tema |
153 | 153 | 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"; |
154 | - return geraXmlRSS($locaplic,$sql,"Lista de temas"); | |
154 | + return geraXmlRSS($locaplic,$sql,"Lista de temas",$output); | |
155 | 155 | } |
156 | 156 | /* |
157 | 157 | Function: geraRSStemasRaiz |
... | ... | @@ -196,12 +196,12 @@ Retorno: |
196 | 196 | |
197 | 197 | RSS |
198 | 198 | */ |
199 | -function geraRSSsubgrupos($locaplic,$id_n1) | |
199 | +function geraRSSsubgrupos($locaplic,$id_n1,$output="json") | |
200 | 200 | { |
201 | 201 | global $esquemaadmin; |
202 | 202 | $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 "; |
203 | 203 | $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"; |
204 | - return geraXmlRSS($locaplic,$sql,"Lista de sub-grupos"); | |
204 | + return geraXmlRSS($locaplic,$sql,"Lista de sub-grupos",$output); | |
205 | 205 | } |
206 | 206 | /* |
207 | 207 | Function: geraRSSgrupos |
... | ... | @@ -216,13 +216,13 @@ Retorno: |
216 | 216 | |
217 | 217 | RSS |
218 | 218 | */ |
219 | -function geraRSSgrupos($locaplic) | |
219 | +function geraRSSgrupos($locaplic,$output="xml") | |
220 | 220 | { |
221 | 221 | global $esquemaadmin; |
222 | 222 | $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 "; |
223 | 223 | $sql .= "from ".$esquemaadmin."i3geoadmin_n1 as n1,".$esquemaadmin."i3geoadmin_grupos as g "; |
224 | 224 | $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"; |
225 | - return geraXmlRSS($locaplic,$sql,"Lista de grupos"); | |
225 | + return geraXmlRSS($locaplic,$sql,"Lista de grupos",$output); | |
226 | 226 | } |
227 | 227 | /* |
228 | 228 | Function: geraXmlDownload |
... | ... | @@ -474,11 +474,13 @@ locaplic {string} - localiza&ccedil;&atilde;o do i3Geo no sistema de arquivos |
474 | 474 | sql {string} - SQL que será aplicado ao sistema de administração |
475 | 475 | |
476 | 476 | descricao {string} - descrição que será inserida no canal RSS |
477 | + | |
478 | +output {string} - xml|json | |
477 | 479 | Retorno: |
478 | 480 | |
479 | 481 | RSS |
480 | 482 | */ |
481 | -function geraXmlRSS($locaplic,$sql,$descricao) | |
483 | +function geraXmlRSS($locaplic,$sql,$descricao,$output="xml") | |
482 | 484 | { |
483 | 485 | global $esquemaadmin; |
484 | 486 | //var_dump($_SERVER);exit; |
... | ... | @@ -497,6 +499,12 @@ function geraXmlRSS($locaplic,$sql,$descricao) |
497 | 499 | $xml .= "<copyright>Gerado pelo i3Geo</copyright>\n"; |
498 | 500 | $xml .= "<language>pt-br</language>\n"; |
499 | 501 | $xml .= "<webmaster></webmaster>\n"; |
502 | + $json = array( | |
503 | + "description"=>$descricao, | |
504 | + "copyright"=>"Gerado pelo i3Geo", | |
505 | + "language"=>"pt-br" | |
506 | + ); | |
507 | + $jsonItems = array(); | |
500 | 508 | $qatlas = $dbh->query($sql); |
501 | 509 | foreach($qatlas as $row) |
502 | 510 | { |
... | ... | @@ -505,8 +513,9 @@ function geraXmlRSS($locaplic,$sql,$descricao) |
505 | 513 | $xml .= "<title>".entity_decode($row["nome_ws"])."</title>\n"; |
506 | 514 | $xml .= "<description>".xmlTexto_prepara(entity_decode($row["desc_ws"]))."</description>\n"; |
507 | 515 | $link = xmlTexto_prepara($row["link_ws"]); |
508 | - if(stristr($link, 'http') === FALSE) | |
509 | - {$link = "http://".$_SERVER["HTTP_HOST"].dirname($_SERVER["REQUEST_URI"])."/".$link;} | |
516 | + if(stristr($link, 'http') === FALSE){ | |
517 | + $link = "http://".$_SERVER["HTTP_HOST"].dirname($_SERVER["REQUEST_URI"])."/".$link; | |
518 | + } | |
510 | 519 | $xml .= "<link><![CDATA[".$link."]]></link>\n"; |
511 | 520 | $xml .= "<pubDate/>\n"; |
512 | 521 | $xml .= "<author>".xmlTexto_prepara($row["autor_ws"])."</author>\n"; |
... | ... | @@ -515,11 +524,25 @@ function geraXmlRSS($locaplic,$sql,$descricao) |
515 | 524 | $xml .= "<id>".xmlTexto_prepara($row["id_ws"])."</id>\n"; |
516 | 525 | $xml .= "<tipo>".$row["tipo_ws"]."</tipo>\n"; |
517 | 526 | $xml .= "</item>\n"; |
527 | + $jsonItems[] = array( | |
528 | + "title"=>$row["nome_ws"], | |
529 | + "description"=>$row["desc_ws"], | |
530 | + "link"=>$link."&output=json", | |
531 | + "author"=>$row["autor_ws"], | |
532 | + "id"=>$row["id_ws"], | |
533 | + "tipo"=>$row["tipo_ws"] | |
534 | + ); | |
518 | 535 | } |
536 | + $json["items"] = $jsonItems; | |
519 | 537 | $xml .= "</channel></rss>\n"; |
520 | 538 | $dbh = null; |
521 | 539 | $dbhw = null; |
522 | - return $xml; | |
540 | + if($output=="xml"){ | |
541 | + return $xml; | |
542 | + } | |
543 | + else{ | |
544 | + return json_encode($json); | |
545 | + } | |
523 | 546 | } |
524 | 547 | function geraXmlAtlas($locaplic,$editores) |
525 | 548 | { | ... | ... |
admin/rssgrupos.php
... | ... | @@ -38,6 +38,10 @@ if(!isset($locaplic)){ |
38 | 38 | } |
39 | 39 | include_once($locaplic."/classesphp/pega_variaveis.php"); |
40 | 40 | include_once($locaplic."/admin/php/xml.php"); |
41 | -echo header("Content-type: application/xml"); | |
42 | -echo geraRSSgrupos($locaplic); | |
41 | +$output = "xml"; | |
42 | +if(strtolower($_GET["output"]) == "json" || strtolower($_POST["output"]) == "json"){ | |
43 | + $output = "json"; | |
44 | +} | |
45 | +echo header("Content-type: application/".$output); | |
46 | +echo geraRSSgrupos($locaplic,$output); | |
43 | 47 | ?> |
44 | 48 | \ No newline at end of file | ... | ... |
admin/rsssubgrupos.php
... | ... | @@ -44,6 +44,10 @@ if(!isset($locaplic)){ |
44 | 44 | } |
45 | 45 | include_once($locaplic."/classesphp/pega_variaveis.php"); |
46 | 46 | include_once($locaplic."/admin/php/xml.php"); |
47 | -echo header("Content-type: application/xml"); | |
48 | -echo geraRSSsubgrupos($locaplic,$id); | |
47 | +$output = "xml"; | |
48 | +if(strtolower($_GET["output"]) == "json" || strtolower($_POST["output"]) == "json"){ | |
49 | + $output = "json"; | |
50 | +} | |
51 | +echo header("Content-type: application/".$output); | |
52 | +echo geraRSSsubgrupos($locaplic,$id,$output); | |
49 | 53 | ?> | ... | ... |
admin/rsstemas.php
... | ... | @@ -44,6 +44,10 @@ if(!isset($locaplic)){ |
44 | 44 | } |
45 | 45 | include_once($locaplic."/classesphp/pega_variaveis.php"); |
46 | 46 | include_once($locaplic."/admin/php/xml.php"); |
47 | -echo header("Content-type: application/xml"); | |
48 | -echo geraRSStemas($locaplic,$id); | |
47 | +$output = "xml"; | |
48 | +if(strtolower($_GET["output"]) == "json" || strtolower($_POST["output"]) == "json"){ | |
49 | + $output = "json"; | |
50 | +} | |
51 | +echo header("Content-type: application/".$output); | |
52 | +echo geraRSStemas($locaplic,$id,$output); | |
49 | 53 | ?> | ... | ... |