From fcc17c052620a108443fea3f6f69d5d89495dc83 Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Mon, 10 Jun 2013 21:26:01 +0000 Subject: [PATCH] Inclusão de uma nova variável em ms_configura.php para controlar a forma como é feito o envio das imagens (tiles do mapa) ao navegador. Inclusão de opção de envio baseado em x-sendfile --- admin/admin.db | Bin 202752 -> 0 bytes classesphp/mapa_googlemaps.php | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- classesphp/mapa_openlayers.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ classesphp/mapa_openlayers_alternativo.php | 8 ++++++-- ms_configura.php | 11 +++++++++++ ms_criamapa.php | 36 +++++++++++++++++++++++------------- 6 files changed, 151 insertions(+), 90 deletions(-) diff --git a/admin/admin.db b/admin/admin.db index 3f02cff..ea7ccb5 100644 Binary files a/admin/admin.db and b/admin/admin.db differ diff --git a/classesphp/mapa_googlemaps.php b/classesphp/mapa_googlemaps.php index e6d8495..56ac5dc 100644 --- a/classesphp/mapa_googlemaps.php +++ b/classesphp/mapa_googlemaps.php @@ -92,6 +92,7 @@ if(!isset($_SESSION["map_file"])){ $map_fileX = $_SESSION["map_file"]; $postgis_mapa = $_SESSION["postgis_mapa"]; $cachedir = $_SESSION["cachedir"]; +$i3georendermode = $_SESSION["i3georendermode"]; // //converte a requisição do tile em coordenadas geo //http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#tile_numbers_to_lon.2Flat_2 @@ -104,7 +105,7 @@ $qyfile = dirname($map_fileX)."/".$_GET["layer"].".php"; $qy = file_exists($qyfile); if($qy == false && $_GET["cache"] == "sim" && $_GET["DESLIGACACHE"] != "sim"){ - carregaCacheImagem($_SESSION["cachedir"],$_SESSION["map_file"],$_GET["tms"]); + carregaCacheImagem(); } $n = pow(2,$z); @@ -297,17 +298,46 @@ if(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum"){ else{ if($cache == true){ $nomer = salvaCacheImagem(); - header('Content-Length: '.filesize($nomer)); - header('Content-Type: image/png'); - header('Cache-Control: max-age=3600, must-revalidate'); - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200); - fpassthru(fopen($nomer, 'rb')); + if($_SESSION["i3georendermode"] == 2){ + ob_clean(); + header("X-Sendfile: $nomer"); + header("Content-type: image/png"); + } + else{ + ob_clean(); + header('Content-Length: '.filesize($nomer)); + header('Content-Type: image/png'); + header('Cache-Control: max-age=3600, must-revalidate'); + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200); + fpassthru(fopen($nomer, 'rb')); + } } else{ - //se der erro aqui veja em mapa_googlemaps_alternativo.php - header('Content-Type: image/png'); - $img->saveImage(); + if($_SESSION["i3georendermode"] == 0){ + $nomer = ($img->imagepath)."temp".nomeRand().".png"; + $img->saveImage($nomer); + $img = imagecreatefrompng($nomer); + imagealphablending($img, false); + imagesavealpha($img, true); + ob_clean(); + echo header("Content-type: image/png \n\n"); + imagepng($img); + imagedestroy($img); + exit; + } + if($_SESSION["i3georendermode"] == 1){ + ob_clean(); + header('Content-Type: image/png'); + $img->saveImage(); + } + if($_SESSION["i3georendermode"] == 2){ + $nomer = ($img->imagepath)."temp".nomeRand().".png"; + $img->saveImage($nomer); + ob_clean(); + header("X-Sendfile: $nomer"); + header("Content-type: image/png"); + } } exit; } @@ -330,7 +360,7 @@ function salvaCacheImagem(){ return $nome; } function carregaCacheImagem(){ - global $img,$cachedir,$x,$y,$z,$map_fileX; + global $img,$cachedir,$x,$y,$z,$map_fileX,$i3georendermode; $layer = $_GET["layer"]; if($layer == "") {$layer = "fundo";} @@ -338,50 +368,20 @@ function carregaCacheImagem(){ $cachedir = dirname(dirname($map_fileX))."/cache"; } $c = $cachedir."/googlemaps/$layer/$z/$x"; - if(file_exists($c."/$y.png")){ - header('Content-Length: '.filesize($c."/$y.png")); - header('Content-Type: image/png'); - fpassthru(fopen($c."/$y.png", 'rb')); - exit; - } -} -/* -function salvaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ - global $img,$map_size; - //layers que são sempre iguais - //error_reporting(0); - if($layer == "copyright" || $layer == "") - {$bbox = "";} - if($layer == "") - {$layer = "fundo";} - if($cachedir == "") - {$cachedir = dirname(dirname($map))."/cache/googlemaps/".$layer;} - else - {$cachedir = $cachedir."/googlemaps/".$layer;} - @mkdir($cachedir,0777); - $nome = $cachedir."/".$w.$h.$bbox.".png"; - if(!file_exists($nome)) - {$img->saveImage($nome);} - return $nome; -} -function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ - if($layer == "copyright" || $layer == "") - {$bbox = "";} - if($layer == "") - {$layer = "fundo";} - $nome = $w.$h.$bbox.".png"; - if($cachedir == "") - {$nome = dirname(dirname($map))."/cache/googlemaps/".$layer."/".$nome;} - else - {$nome = $cachedir."/googlemaps/".$layer."/".$nome;} + $nome = $c."/$y.png"; if(file_exists($nome)){ - header('Content-Length: '.filesize($nome)); - header('Content-Type: image/png'); - fpassthru(fopen($nome, 'rb')); + if($i3georendermode = 0 || $i3georendermode = 1 || empty($i3georendermode)){ + header('Content-Length: '.filesize($nome)); + header('Content-Type: image/png'); + fpassthru(fopen($nome, 'rb')); + } + else{ + header("X-Sendfile: $nome"); + header("Content-type: image/png"); + } exit; } } -*/ function nomeRand($n=10) { $nomes = ""; diff --git a/classesphp/mapa_openlayers.php b/classesphp/mapa_openlayers.php index b38b2b9..a1ffbe0 100644 --- a/classesphp/mapa_openlayers.php +++ b/classesphp/mapa_openlayers.php @@ -5,11 +5,12 @@ Title: mapa_openlayers.php Faz o processamento de um mapfile segundo as necessidades do i3geo, como por exemplo, fazendo a substituição das variáveis de conexão com banco e outras operações específicas do i3Geo. -É utilizado especificamente nas interfaces que utilizam a biblioteca OpenLayers em LAYERS do tipo WMS. +É utilizado especificamente nas interfaces que utilizam a biblioteca OpenLayers. -Precisa do codigo da "section" PHP aberta pelo i3Geo ou o codigo para acesso especial indicado no parâmetro telaR +Precisa do codigo da "section" PHP aberta pelo i3Geo (veja ms_criamapa.php) ou o codigo para acesso especial indicado no parâmetro telaR (veja a ferramenta TELAREMOTA). + Parametros: g_sid {string} - código da "section" PHP @@ -93,7 +94,7 @@ $qyfile = dirname($map_fileX)."/".$_GET["layer"].".php"; $qy = file_exists($qyfile); if($qy == false && $_GET["cache"] == "sim" && $_GET["DESLIGACACHE"] != "sim"){ - carregaCacheImagem($_SESSION["cachedir"],$_SESSION["map_file"],$_GET["tms"]); + carregaCacheImagem($_SESSION["cachedir"],$_SESSION["map_file"],$_GET["tms"],$_SESSION["i3georendermode"]); } // //map_fileX e para o caso register_globals = On no PHP.INI @@ -259,13 +260,14 @@ else{ $status = $l->whichShapes($mapa->extent); while ($shape = $l->nextShape()) { - if(in_array($shape->index,$shp)) - $shape->draw($mapa,$l,$img); + if(in_array($shape->index,$shp)) + $shape->draw($mapa,$l,$img); } $l->close(); } $cache = false; } +//nao usa o cache pois e necessario processar a imagem com alguma rotina de filtro if($_GET["TIPOIMAGEM"] != "" && $_GET["TIPOIMAGEM"] != "nenhum"){ if($img->imagepath == "") {echo "Erro IMAGEPATH vazio";exit;} @@ -282,21 +284,51 @@ if($_GET["TIPOIMAGEM"] != "" && $_GET["TIPOIMAGEM"] != "nenhum"){ } else{ if($cache == true && $_GET["cache"] != "nao"){ - //$nomer = salvaCacheImagem($cachedir,$_GET["BBOX"],$nomecache,$map_fileX,$_GET["WIDTH"],$_GET["HEIGHT"]); + //cache ativo. Salva a imagem em cache $nomer = salvaCacheImagem($cachedir,$map_fileX,$_GET["tms"]); - header('Content-Length: '.filesize($nomer)); - header('Content-Type: image/png'); - header('Cache-Control: max-age=3600, must-revalidate'); - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200); - fpassthru(fopen($nomer, 'rb')); + if($_SESSION["i3georendermode"] == 2){ + ob_clean(); + header("X-Sendfile: $nomer"); + header("Content-type: image/png"); + } + else{ + ob_clean(); + header('Content-Length: '.filesize($nomer)); + header('Content-Type: image/png'); + header('Cache-Control: max-age=3600, must-revalidate'); + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200); + fpassthru(fopen($nomer, 'rb')); + } } else{ + //cache inativo if($img->imagepath == "") {echo "Erro IMAGEPATH vazio";exit;} - //se der erro aqui veja em mapa_openlayers_alternativo.php - header('Content-Type: image/png'); - $img->saveImage(); + if($_SESSION["i3georendermode"] == 0){ + $nomer = ($img->imagepath)."temp".nomeRand().".png"; + $img->saveImage($nomer); + $img = imagecreatefrompng($nomer); + imagealphablending($img, false); + imagesavealpha($img, true); + ob_clean(); + echo header("Content-type: image/png \n\n"); + imagepng($img); + imagedestroy($img); + exit; + } + if($_SESSION["i3georendermode"] == 1){ + ob_clean(); + header('Content-Type: image/png'); + $img->saveImage(); + } + if($_SESSION["i3georendermode"] == 2){ + $nomer = ($img->imagepath)."temp".nomeRand().".png"; + $img->saveImage($nomer); + ob_clean(); + header("X-Sendfile: $nomer"); + header("Content-type: image/png"); + } } } function salvaCacheImagem($cachedir,$map,$tms){ @@ -315,7 +347,7 @@ function salvaCacheImagem($cachedir,$map,$tms){ } return $nome; } -function carregaCacheImagem($cachedir,$map,$tms){ +function carregaCacheImagem($cachedir,$map,$tms,$i3georendermode=0){ if($cachedir == ""){ $nome = dirname(dirname($map))."/cache".$tms; } @@ -323,14 +355,18 @@ function carregaCacheImagem($cachedir,$map,$tms){ $nome = $cachedir.$tms; } if(file_exists($nome)){ - header('Content-Length: '.filesize($nome)); - header('Content-Type: image/png'); - header('Cache-Control: max-age=3600, must-revalidate'); - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT'); - header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nome)).' GMT', true, 200); - $etag = md5_file($nome); - header('Etag: '.$etag); - fpassthru(fopen($nome, 'rb')); + if($i3georendermode = 0 || $i3georendermode = 1 || empty($i3georendermode)){ + header('Content-Length: '.filesize($nome)); + header('Content-Type: image/png'); + header('Cache-Control: max-age=3600, must-revalidate'); + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nome)).' GMT', true, 200); + fpassthru(fopen($nome, 'rb')); + } + else{ + header("X-Sendfile: $nome"); + header("Content-type: image/png"); + } exit; } } diff --git a/classesphp/mapa_openlayers_alternativo.php b/classesphp/mapa_openlayers_alternativo.php index 56cbe01..5c530ef 100644 --- a/classesphp/mapa_openlayers_alternativo.php +++ b/classesphp/mapa_openlayers_alternativo.php @@ -59,6 +59,10 @@ i3geo/classesphp/mapa_openlayers.php */ error_reporting(0); +//para efeitos de compatibilidade +if (!function_exists('ms_GetVersion')){ + include_once ("carrega_ext.php"); +} //carrega dados da seção, verifica segurança inicializa(); // @@ -255,8 +259,8 @@ else{ $status = $l->whichShapes($mapa->extent); while ($shape = $l->nextShape()) { - if(in_array($shape->index,$shp)) - $shape->draw($mapa,$l,$img); + if(in_array($shape->index,$shp)) + $shape->draw($mapa,$l,$img); } $l->close(); } diff --git a/ms_configura.php b/ms_configura.php index 8120d91..d928c9c 100644 --- a/ms_configura.php +++ b/ms_configura.php @@ -63,6 +63,17 @@ $i3geomaster = array( array("usuario"=>"admin", "senha"=>"admin") ); /* + Variable: i3georendermode + + Opcoes que definem a rotina que sera utilizada para enviar ao navegador as imagens geradas de cada camada + + 0 - modo default. Utiliza a funcao imagepng() do PHP para enviar a imagem ao navegador + 1 - utiliza a funcao do Mapserver saveImage() para enviar a imagem ao navegador (e mais rapida, mas nao funciona em algumas versoes do Mapserver) + 2 - utiliza X-Sendfile (mais rapido que as outras opcoes) mas exige modificacoes na instalacao do Apache. Veja em: https://tn123.org/mod_xsendfile/ e http://edmarmoretti.blogspot.com.br/ + */ +//@TODO documentar no manual de administracao +$i3georendermode = 0; +/* Variavel: linkedinoauth (ainda não implementado) Parâmetros registrados no Linkedin para permitir que o i3Geo faça autenticação com base na conta do usuário diff --git a/ms_criamapa.php b/ms_criamapa.php index e3d7903..e48ec09 100644 --- a/ms_criamapa.php +++ b/ms_criamapa.php @@ -145,7 +145,7 @@ else if(!isset($funcao)) {ob_end_clean();} /* - Carrega as extensões PHP +Carrega as extensões PHP Carrega as extensões utilizadas no programa de inicialização. A carga das extensões geralmente é necessária nas instalações windows (ms4w) ou quando as mesmas não são carregadas pela própria inicialização do PHP. @@ -232,7 +232,7 @@ criaIndex(); $tmpfname = $diretorios[0]; $protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']); /* - Prepara as variáveis que serão incluidas na seção +Prepara as variáveis que serão incluidas na seção As variáveis vêm do arquivo ms_configura.php e são armazenadas em uma seção com nome específico para o i3geo. */ @@ -262,24 +262,33 @@ $expoeMapfile_ = $expoeMapfile; $googleApiKey_ = $googleApiKey; $mensagemInicia_ = $mensagemInicia; $interfacePadrao_ = $interfacePadrao; -if(isset($interface)){$interface_ = $interface;} +if(isset($interface)) +{$interface_ = $interface;} else{$interface_ = $interfacePadrao;} -if(isset($kmlurl)){$kmlurl_ = $kmlurl;} +if(isset($kmlurl)) +{$kmlurl_ = $kmlurl;} // //se houver string de conexão para substituição //o modo cgi não irá funcionar // if($postgis_mapa != "") {$utilizacgi = "nao";} -if(!isset($perfil)){$perfil="";} +if(!isset($perfil)) +{$perfil="";} $perfil_ = $perfil; $utilizacgi_ = $utilizacgi; if ((isset($navegadoresLocais)) && ($navegadoresLocais != "")) -$navegadoresLocais_ = "sim"; +{$navegadoresLocais_ = "sim";} else -$navegadoresLocais_ = "nao"; +{$navegadoresLocais_ = "nao";} +if(empty($i3georendermode)){ + $i3georendermode_ = 0; +} +else{ + $i3georendermode_ = $i3georendermode; +} /* - Inicia a seção +Inicia a seção O i3geo inicia uma seção específica no servidor, denominada i3GeoPHP. Se já houver uma seção aberta, em função de outro browser estar ativo, cria uma nova. Faz a cópia das variáveis definidas para itens da seção. @@ -291,7 +300,7 @@ if (!isset($g_sid)){$g_sid="";} if(isset($_SESSION["map_file"]) || $g_sid != "" || $g_sid == "undefined") {session_regenerate_id();$_SESSION = array();} /* - Aguarde +Aguarde Monta a apresentação do aguarde. @@ -330,6 +339,7 @@ $_SESSION['fingerprint'] = md5($fingerprint . session_id()); $_SESSION["mapdir"] = $diretorios[1]; $_SESSION["imgdir"] = $diretorios[2]; $_SESSION["contadorsalva"] = 0;//essa variavel e utilizada pela ferramenta telaremota. Toda vez que o mapa e salvo, acrescenta 1 (veja classesphp/mapa_controle.php) +$_SESSION["i3georendermode"] = $i3georendermode_; // //pega todas as variáveis da sessão, mesmo as que foram definidas anteriormente // @@ -338,7 +348,7 @@ foreach(array_keys($_SESSION) as $k) {eval("\$".$k."='".$_SESSION[$k]."';");} $postgis_mapa = $postgis_mapa_; /* - Define os arquivos .map +Define os arquivos .map Seleciona os arquivos mapfile que serão carregados como base conforme o tipo de sistema operacional. @@ -372,7 +382,7 @@ if(!isset($base) || $base == "") //if(!isset($estadosl)) //{$estadosl = "estadosl";} /* - Cria os objetos map que serão processados +Cria os objetos map que serão processados O arquivo definido em $base é lido como um objeto map. Esse objeto será processado para incluir novos layers e alterar outros parâmetros definidos pelo usuário. */ @@ -394,7 +404,7 @@ if(!empty($gvsiggvp)){ incluiMapaGvsig($gvsiggvp,$gvsigview); } /* - Parâmetros adicionais. +Parâmetros adicionais. Processa os parâmetros para a inicialização verificando se foram passados pela URL ou não. */ @@ -1141,7 +1151,7 @@ function incluiTemaWms() else $nome = $nome_wms; $m = new Mapa($tmpfname); - $m->adicionatemawms($layer_wms,$url_wms,$style_wms,$srs_wms,$image_wms,$locaplic,"",$versao_wms,$nome,"","","","","nao","text/plain",""); + $m->adicionatemawms($layer_wms,$url_wms,$style_wms,$srs_wms,$image_wms,$locaplic,"",$versao_wms,$nome,"","","","","nao","text/plain",""); $salvo = $m->salva($tmpfname); //echo $tmpfname;exit; erroCriacao(); -- libgit2 0.21.2