From dc3eadc00af75f9290afdaaba1b94873f85c5c0f Mon Sep 17 00:00:00 2001 From: franzz Date: Sat, 23 Mar 2019 14:43:50 +0100 Subject: [PATCH] Push Cacher to Objects (WMTS Class) --- cache/.gitignore | 1 - inc/cacher.php | 109 ----------------------------------------------- inc/spot.php | 40 ++--------------- 3 files changed, 3 insertions(+), 147 deletions(-) delete mode 100644 cache/.gitignore delete mode 100644 inc/cacher.php diff --git a/cache/.gitignore b/cache/.gitignore deleted file mode 100644 index cae6c9a..0000000 --- a/cache/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.tile diff --git a/inc/cacher.php b/inc/cacher.php deleted file mode 100644 index 96babb2..0000000 --- a/inc/cacher.php +++ /dev/null @@ -1,109 +0,0 @@ -setPattern($sPattern); - $this->setId($sId); - $this->iX = 0; - $this->iY = 0; - $this->iZ = 0; - $this->sToken = ''; - $this->asDomains = array(); - $this->sReferer = ''; - } - - public function setId($sId) { - $this->sId = $sId; - } - - public function setPattern($sPattern) { - $this->sPattern = $sPattern; - } - - public function setToken($sToken) { - $this->sToken = $sToken; - } - - public function setDomains($asDomains) { - $this->asDomains = $asDomains; - } - - public function setReferer($sReferer) { - $this->sReferer = $sReferer; - } - - public function setGeoPos($iX, $iY, $iZ) { - $this->iX = $iX; - $this->iY = $iY; - $this->iZ = $iZ; - } - - public function pushTile($iX, $iY, $iZ) { - $this->setGeoPos($iX, $iY, $iZ); - $sTilePath = $this->getFilePath(); - if(!$this->isFileAvailable($sTilePath)) { - $oCurl = curl_init(); - curl_setopt($oCurl, CURLOPT_URL, $this->getUrl()); - curl_setopt($oCurl, CURLOPT_HEADER, false); - curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($oCurl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); - curl_setopt($oCurl, CURLOPT_REFERER, $this->sReferer); - $sContent = curl_exec($oCurl); - curl_close($oCurl); - - file_put_contents($sTilePath, $sContent); - } - else $sContent = file_get_contents($sTilePath); - - header('Content-type: '.mime_content_type($sTilePath)); - return $sContent; - } - - public function getUrl() { - $asParams = $this->getUrlParams(); - $sUrl = $this->sPattern; - foreach($asParams as $sParam=>$sValue) { - $sUrl = str_replace('{'.$sParam.'}', $sValue, $sUrl); - } - return $sUrl; - } - - private function isFileAvailable($sTilePath) { - if(!file_exists($sTilePath)) return false; - else return (time() - filemtime($sTilePath) < self::DATA_RETENTION); - } - - private function getFilePath() { - $asParams = $this->getUrlParams(); - return self::CACHE_FOLDER.'/'.$asParams['id'].'_'.$asParams['x'].'_'.$asParams['y'].'_'.$asParams['z'].'.tile'; - } - - private function getUrlParams() { - return array( - 'id' => $this->sId, - 'x' => $this->iX, - 'y' => $this->iY, - 'z' => $this->iZ, - 'token' => $this->sToken, - 's' => empty($this->asDomains)?'':$this->asDomains[array_rand($this->asDomains)] - ); - } -} - diff --git a/inc/spot.php b/inc/spot.php index 26ba379..acb2754 100755 --- a/inc/spot.php +++ b/inc/spot.php @@ -41,7 +41,7 @@ class Spot extends Main array('name'=>'feed', 'project'=>true), array('name'=>'project', 'project'=>true), array('name'=>'picture', 'project'=>true), - array('name'=>'cacher', 'project'=>true), + array('name'=>'wmts', 'project'=>false), array('name'=>'converter', 'project'=>true) ); parent::__construct($oClassManagement, $sProcessPage, $asClasses); @@ -331,42 +331,8 @@ class Spot extends Main public function getTile($sMapId, $iX, $iY, $iZ) { if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == $this->asContext['serv_name'] || Settings::DEBUG) { - $asDomains = array(); - $sReferer = Settings::HOST_SERVER; - switch($sMapId) { - case 'mapbox.satellite': - case 'mapbox.streets': - $sPattern = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}@2x.png?access_token={token}'; - $sToken = Settings::MAPBOX_KEY; - break; - case 'linz': - $sPattern = 'http://tiles-{s}.data-cdn.linz.govt.nz/services;key={token}/tiles/v4/layer=50767/EPSG:3857/{z}/{x}/{y}.png'; - $sToken = Settings::LINZ_KEY; - $asDomains = array('a', 'b', 'c', 'd'); - break; - case 'ign.es': - $sPattern = 'http://www.ign.es/wmts/mapa-raster?request=getTile&format=image/png&layer=MTN&TileMatrixSet=GoogleMapsCompatible&TileMatrix={z}&TileCol={x}&TileRow={y}'; - break; - case 'ign.fr': - $sPattern = 'https://wxs.ign.fr/{token}/geoportail/wmts?LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&EXCEPTIONS=text/xml&FORMAT=image/jpeg&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal&TILEMATRIXSET=PM&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}'; - $sToken = Settings::IGN_FR_KEY; - $sReferer = 'https://www.visugpx.com/yfJDwfuTlf'; - break; - case 'opentopomap': - $sPattern = 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png'; - $asDomains = array('a', 'b', 'c'); - break; - case 'static': - $sPattern = 'https://api.mapbox.com/v4/mapbox.satellite/url-'.urlencode(Settings::HOST_SERVER).'%2Fimages%2Ffootprint_mapbox.png({x},{y})/{x},{y},{z}/400x300.png?access_token={token}'; - $sToken = Settings::MAPBOX_KEY; - break; - } - $oCacher = new Cacher($sPattern, $sMapId); - $oCacher->setToken($sToken); - $oCacher->setDomains($asDomains); - $oCacher->setReferer($sReferer); - - return $oCacher->pushTile($iX, $iY, $iZ); + $oWmts = new Wmts($sMapId); + return $oWmts->pushTile($iX, $iY, $iZ); } else { header('HTTP/1.1 403 Forbidden');