Completed
Push — master ( 3e13e1...ba9fdc )
by Mark
17s queued 13s
created
helper/staticmap.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
 
81 81
         // normalize zoom
82 82
         $zoom = $zoom ?: 0;
83
-        if($zoom > 18) {
83
+        if ($zoom > 18) {
84 84
             $zoom = 18;
85 85
         }
86 86
         // normalize WxH
87 87
         list($width, $height) = explode('x', $size);
88 88
         $width = (int) $width;
89
-        if($width > $this->maxWidth) {
89
+        if ($width > $this->maxWidth) {
90 90
             $width = $this->maxWidth;
91 91
         }
92 92
         $height = (int) $height;
93
-        if($height > $this->maxHeight) {
93
+        if ($height > $this->maxHeight) {
94 94
             $height = $this->maxHeight;
95 95
         }
96 96
 
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
      */
126 126
     private function mediaIdToPath(string $id): string {
127 127
         global $conf;
128
-        if(empty($id)) {
128
+        if (empty($id)) {
129 129
             return "";
130 130
         }
131 131
         $id = str_replace(array("[[", "]]"), "", $id);
132
-        if((strpos($id, ':') === 0)) {
132
+        if ((strpos($id, ':') === 0)) {
133 133
             $id = substr($id, 1);
134 134
         }
135 135
         $id = str_replace(":", "/", $id);
136
-        return $conf['mediadir'] . '/' . $id;
136
+        return $conf['mediadir'].'/'.$id;
137 137
     }
138 138
 }
Please login to merge, or discard this patch.
StaticMap.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
         $this->height = $height;
215 215
         // validate + set maptype
216 216
         $this->maptype = $this->tileDefaultSrc;
217
-        if(array_key_exists($maptype, $this->tileInfo)) {
217
+        if (array_key_exists($maptype, $this->tileInfo)) {
218 218
             $this->maptype = $maptype;
219 219
         }
220 220
         $this->markers          = $markers;
@@ -222,9 +222,9 @@  discard block
 block discarded – undo
222 222
         $this->gpxFileName      = $gpx;
223 223
         $this->geojsonFileName  = $geojson;
224 224
         $this->mediaBaseDir     = $mediaDir;
225
-        $this->tileCacheBaseDir = $tileCacheBaseDir . '/olmaptiles';
225
+        $this->tileCacheBaseDir = $tileCacheBaseDir.'/olmaptiles';
226 226
         $this->useTileCache     = $this->tileCacheBaseDir !== '';
227
-        $this->mapCacheBaseDir  = $mediaDir . '/olmapmaps';
227
+        $this->mapCacheBaseDir  = $mediaDir.'/olmapmaps';
228 228
         $this->autoZoomExtent   = $autoZoomExtent;
229 229
         $this->apikey           = $apikey;
230 230
     }
@@ -236,15 +236,15 @@  discard block
 block discarded – undo
236 236
      */
237 237
     public function getMap(): string {
238 238
         try {
239
-            if($this->autoZoomExtent) {
239
+            if ($this->autoZoomExtent) {
240 240
                 $this->autoZoom();
241 241
             }
242
-        } catch(Exception $e) {
242
+        } catch (Exception $e) {
243 243
             dbglog($e);
244 244
         }
245 245
 
246 246
         // use map cache, so check cache for map
247
-        if(!$this->checkMapCache()) {
247
+        if (!$this->checkMapCache()) {
248 248
             // map is not in cache, needs to be build
249 249
             $this->makeMap();
250 250
             $this->mkdirRecursive(dirname($this->mapCacheIDToFilename()), 0777);
@@ -264,37 +264,37 @@  discard block
 block discarded – undo
264 264
      */
265 265
     private function autoZoom(float $paddingFactor = 1.0): void {
266 266
         $geoms    = array();
267
-        $geoms [] = new Point ($this->lon, $this->lat);
268
-        if(!empty ($this->markers)) {
269
-            foreach($this->markers as $marker) {
270
-                $geoms [] = new Point ($marker ['lon'], $marker ['lat']);
267
+        $geoms [] = new Point($this->lon, $this->lat);
268
+        if (!empty ($this->markers)) {
269
+            foreach ($this->markers as $marker) {
270
+                $geoms [] = new Point($marker ['lon'], $marker ['lat']);
271 271
             }
272 272
         }
273
-        if(file_exists($this->kmlFileName)) {
273
+        if (file_exists($this->kmlFileName)) {
274 274
             $g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
275
-            if($g !== false) {
275
+            if ($g !== false) {
276 276
                 $geoms [] = $g;
277 277
             }
278 278
         }
279
-        if(file_exists($this->gpxFileName)) {
279
+        if (file_exists($this->gpxFileName)) {
280 280
             $g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
281
-            if($g !== false) {
281
+            if ($g !== false) {
282 282
                 $geoms [] = $g;
283 283
             }
284 284
         }
285
-        if(file_exists($this->geojsonFileName)) {
285
+        if (file_exists($this->geojsonFileName)) {
286 286
             $g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson');
287
-            if($g !== false) {
287
+            if ($g !== false) {
288 288
                 $geoms [] = $g;
289 289
             }
290 290
         }
291 291
 
292
-        if(count($geoms) <= 1) {
292
+        if (count($geoms) <= 1) {
293 293
             dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options");
294 294
             return;
295 295
         }
296 296
 
297
-        $geom     = new GeometryCollection ($geoms);
297
+        $geom     = new GeometryCollection($geoms);
298 298
         $centroid = $geom->centroid();
299 299
         $bbox     = $geom->getBBox();
300 300
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
         $vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360)));
304 304
         $vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360)));
305 305
         dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1");
306
-        if ($vy1 - $vy0 === 0.0){
306
+        if ($vy1 - $vy0 === 0.0) {
307 307
             $resolutionVertical = 0;
308 308
             dbglog("StaticMap::autoZoom: using $resolutionVertical");
309 309
         } else {
@@ -315,11 +315,11 @@  discard block
 block discarded – undo
315 315
         dbglog("StaticMap::autoZoom: using $resolutionHorizontal");
316 316
         $resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
317 317
         $zoom                 = $this->zoom;
318
-        if ($resolution > 0){
318
+        if ($resolution > 0) {
319 319
             $zoom             = log(360 / ($resolution * $this->tileSize), 2);
320 320
         }
321 321
 
322
-        if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
322
+        if (is_finite($zoom) && $zoom < 15 && $zoom > 2) {
323 323
             $this->zoom = floor($zoom);
324 324
         }
325 325
         $this->lon = $centroid->getX();
@@ -352,12 +352,12 @@  discard block
 block discarded – undo
352 352
     }
353 353
 
354 354
     public function mapCacheIDToFilename(): string {
355
-        if(!$this->mapCacheFile) {
356
-            $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_"
357
-                . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2)
358
-                . "/" . substr($this->mapCacheID, 4);
355
+        if (!$this->mapCacheFile) {
356
+            $this->mapCacheFile = $this->mapCacheBaseDir."/".$this->maptype."/".$this->zoom."/cache_"
357
+                . substr($this->mapCacheID, 0, 2)."/".substr($this->mapCacheID, 2, 2)
358
+                . "/".substr($this->mapCacheID, 4);
359 359
         }
360
-        return $this->mapCacheFile . "." . $this->mapCacheExtension;
360
+        return $this->mapCacheFile.".".$this->mapCacheExtension;
361 361
     }
362 362
 
363 363
     /**
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
     public function makeMap(): void {
367 367
         $this->initCoords();
368 368
         $this->createBaseMap();
369
-        if(!empty ($this->markers)) {
369
+        if (!empty ($this->markers)) {
370 370
             $this->placeMarkers();
371 371
         }
372 372
         if (file_exists($this->kmlFileName)) {
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
         $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
440 440
         $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
441 441
 
442
-        for($x = $startX; $x <= $endX; $x++) {
443
-            for($y = $startY; $y <= $endY; $y++) {
442
+        for ($x = $startX; $x <= $endX; $x++) {
443
+            for ($y = $startY; $y <= $endY; $y++) {
444 444
                 $url = str_replace(
445 445
                     array(
446 446
                         '{Z}',
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
                 );
455 455
 
456 456
                 $tileData = $this->fetchTile($url);
457
-                if($tileData) {
457
+                if ($tileData) {
458 458
                     $tileImage = imagecreatefromstring($tileData);
459 459
                 } else {
460 460
                     $tileImage = imagecreate($this->tileSize, $this->tileSize);
@@ -480,17 +480,17 @@  discard block
 block discarded – undo
480 480
      *          for better proxy handling...
481 481
      */
482 482
     public function fetchTile(string $url) {
483
-        if($this->useTileCache && ($cached = $this->checkTileCache($url)))
483
+        if ($this->useTileCache && ($cached = $this->checkTileCache($url)))
484 484
             return $cached;
485 485
 
486
-        $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')';
487
-        if(function_exists("curl_init")) {
486
+        $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; '.PHP_OS.')';
487
+        if (function_exists("curl_init")) {
488 488
             // use cUrl
489 489
             $ch = curl_init();
490 490
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
491 491
             curl_setopt($ch, CURLOPT_USERAGENT, $_UA);
492 492
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
493
-            curl_setopt($ch, CURLOPT_URL, $url . $this->apikey);
493
+            curl_setopt($ch, CURLOPT_URL, $url.$this->apikey);
494 494
             dbglog("StaticMap::fetchTile: getting: $url using curl_exec");
495 495
             $tile = curl_exec($ch);
496 496
             curl_close($ch);
@@ -500,21 +500,21 @@  discard block
 block discarded – undo
500 500
             $opts = array(
501 501
                 'http' => array(
502 502
                     'method'          => "GET",
503
-                    'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
503
+                    'header'          => "Accept-language: en\r\n"."User-Agent: $_UA\r\n"."accept: image/png\r\n",
504 504
                     'request_fulluri' => true
505 505
                 )
506 506
             );
507
-            if(isset($conf['proxy']['host'], $conf['proxy']['port'])
507
+            if (isset($conf['proxy']['host'], $conf['proxy']['port'])
508 508
                 && $conf['proxy']['host'] !== ''
509 509
                 && $conf['proxy']['port'] !== '') {
510
-                $opts['http'] += ['proxy' => "tcp://" . $conf['proxy']['host'] . ":" . $conf['proxy']['port']];
510
+                $opts['http'] += ['proxy' => "tcp://".$conf['proxy']['host'].":".$conf['proxy']['port']];
511 511
             }
512 512
 
513 513
             $context = stream_context_create($opts);
514 514
             dbglog("StaticMap::fetchTile: getting: $url . $this->apikey using file_get_contents and options $opts");
515
-            $tile = file_get_contents($url . $this->apikey, false, $context);
515
+            $tile = file_get_contents($url.$this->apikey, false, $context);
516 516
         }
517
-        if($tile && $this->useTileCache) {
517
+        if ($tile && $this->useTileCache) {
518 518
             $this->writeTileToCache($url, $tile);
519 519
         }
520 520
         return $tile;
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
      */
528 528
     public function checkTileCache(string $url) {
529 529
         $filename = $this->tileUrlToFilename($url);
530
-        if(file_exists($filename)) {
530
+        if (file_exists($filename)) {
531 531
             return file_get_contents($filename);
532 532
         }
533 533
         return false;
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
      * @return string
540 540
      */
541 541
     public function tileUrlToFilename(string $url): string {
542
-        return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
542
+        return $this->tileCacheBaseDir."/".substr($url, strpos($url, '/') + 1);
543 543
     }
544 544
 
545 545
     /**
@@ -574,14 +574,14 @@  discard block
 block discarded – undo
574 574
         $count         = 0;
575 575
         $color         = imagecolorallocate($this->image, 0, 0, 0);
576 576
         $bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
577
-        $markerBaseDir = __DIR__ . '/icons';
577
+        $markerBaseDir = __DIR__.'/icons';
578 578
         $markerImageOffsetX  = 0;
579 579
         $markerImageOffsetY  = 0;
580 580
         $markerShadowOffsetX = 0;
581 581
         $markerShadowOffsetY = 0;
582 582
         $markerShadowImg     = null;
583 583
         // loop thru marker array
584
-        foreach($this->markers as $marker) {
584
+        foreach ($this->markers as $marker) {
585 585
             // set some local variables
586 586
             $markerLat  = $marker ['lat'];
587 587
             $markerLon  = $marker ['lon'];
@@ -591,18 +591,18 @@  discard block
 block discarded – undo
591 591
             $markerShadow   = '';
592 592
             $matches        = false;
593 593
             // check for marker type, get settings from markerPrototypes
594
-            if($markerType) {
595
-                foreach($this->markerPrototypes as $markerPrototype) {
596
-                    if(preg_match($markerPrototype ['regex'], $markerType, $matches)) {
597
-                        $markerFilename = $matches [0] . $markerPrototype ['extension'];
598
-                        if($markerPrototype ['offsetImage']) {
594
+            if ($markerType) {
595
+                foreach ($this->markerPrototypes as $markerPrototype) {
596
+                    if (preg_match($markerPrototype ['regex'], $markerType, $matches)) {
597
+                        $markerFilename = $matches [0].$markerPrototype ['extension'];
598
+                        if ($markerPrototype ['offsetImage']) {
599 599
                             list ($markerImageOffsetX, $markerImageOffsetY) = explode(
600 600
                                 ",",
601 601
                                 $markerPrototype ['offsetImage']
602 602
                             );
603 603
                         }
604 604
                         $markerShadow = $markerPrototype ['shadow'];
605
-                        if($markerShadow) {
605
+                        if ($markerShadow) {
606 606
                             list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
607 607
                                 ",",
608 608
                                 $markerPrototype ['offsetShadow']
@@ -612,14 +612,14 @@  discard block
 block discarded – undo
612 612
                 }
613 613
             }
614 614
             // create img resource
615
-            if(file_exists($markerBaseDir . '/' . $markerFilename)) {
616
-                $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
615
+            if (file_exists($markerBaseDir.'/'.$markerFilename)) {
616
+                $markerImg = imagecreatefrompng($markerBaseDir.'/'.$markerFilename);
617 617
             } else {
618
-                $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
618
+                $markerImg = imagecreatefrompng($markerBaseDir.'/marker.png');
619 619
             }
620 620
             // check for shadow + create shadow recource
621
-            if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
622
-                $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
621
+            if ($markerShadow && file_exists($markerBaseDir.'/'.$markerShadow)) {
622
+                $markerShadowImg = imagecreatefrompng($markerBaseDir.'/'.$markerShadow);
623 623
             }
624 624
             // calc position
625 625
             $destX = floor(
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
                 $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
632 632
             );
633 633
             // copy shadow on basemap
634
-            if($markerShadow && $markerShadowImg) {
634
+            if ($markerShadow && $markerShadowImg) {
635 635
                 imagecopy(
636 636
                     $this->image,
637 637
                     $markerShadowImg,
@@ -693,14 +693,14 @@  discard block
 block discarded – undo
693 693
      *            drawing colour
694 694
      */
695 695
     private function drawGeometry(Geometry $geom, int $colour): void {
696
-        if(empty($geom)) {
696
+        if (empty($geom)) {
697 697
             return;
698 698
         }
699 699
 
700
-        switch($geom->geometryType()) {
700
+        switch ($geom->geometryType()) {
701 701
             case 'GeometryCollection' :
702 702
                 // recursively draw part of the collection
703
-                for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
703
+                for ($i = 1; $i < $geom->numGeometries() + 1; $i++) {
704 704
                     $_geom = $geom->geometryN($i);
705 705
                     $this->drawGeometry($_geom, $colour);
706 706
                 }
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
         // extring is a linestring actually..
743 743
         $extRing = $polygon->exteriorRing();
744 744
 
745
-        for($i = 1; $i < $extRing->numGeometries(); $i++) {
745
+        for ($i = 1; $i < $extRing->numGeometries(); $i++) {
746 746
             $p1           = $extRing->geometryN($i);
747 747
             $x            = floor(
748 748
                 ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
      */
769 769
     private function drawLineString($line, $colour) {
770 770
         imagesetthickness($this->image, 2);
771
-        for($p = 1; $p < $line->numGeometries(); $p++) {
771
+        for ($p = 1; $p < $line->numGeometries(); $p++) {
772 772
             // get first pair of points
773 773
             $p1 = $line->geometryN($p);
774 774
             $p2 = $line->geometryN($p + 1);
@@ -841,8 +841,8 @@  discard block
 block discarded – undo
841 841
      * add copyright and origin notice and icons to the map.
842 842
      */
843 843
     public function drawCopyright() {
844
-        $logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
845
-        $logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
844
+        $logoBaseDir = dirname(__FILE__).'/'.'logo/';
845
+        $logoImg     = imagecreatefrompng($logoBaseDir.$this->tileInfo ['openstreetmap'] ['logo']);
846 846
         $textcolor   = imagecolorallocate($this->image, 0, 0, 0);
847 847
         $bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
848 848
 
@@ -875,11 +875,11 @@  discard block
 block discarded – undo
875 875
 
876 876
         // additional tile source info, ie. who created/hosted the tiles
877 877
         $xIconOffset = 0;
878
-        if($this->maptype === 'openstreetmap') {
878
+        if ($this->maptype === 'openstreetmap') {
879 879
             $mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
880 880
         } else {
881 881
             $mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
882
-            $iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
882
+            $iconImg     = imagecreatefrompng($logoBaseDir.$this->tileInfo [$this->maptype] ['logo']);
883 883
             $xIconOffset = imagesx($iconImg);
884 884
             imagecopy(
885 885
                 $this->image,
Please login to merge, or discard this patch.