]> git.nbdom.net Git - nb.git/commitdiff
lib/php/maps.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 8 Jan 2018 20:30:18 +0000 (20:30 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 8 Jan 2018 20:30:18 +0000 (20:30 +0000)
etc/dbq/pub.php
lib/php/maps.php

index 164a88bf53d4e6086041e38c9f840d63ff9ad10e..d725af38311022e98ea6757c62cefb463e096827 100644 (file)
@@ -9,6 +9,6 @@ if ($html) {
 }
 
 $DBQ['pub'] = [
-       'row_parse_post' => !$html ? null : function(&$r,&$t) { Maps::html($r); },
+       'row_parse_post' => !$html ? null : function(&$r,&$t) { Maps::row($r); },
 ];
 ?>
index ae3f7d0bb810c4af7ca1d7eeee0acc4d43918573..ef3b3d27db7f3f08152c41d24e92ee017e40a1b0 100644 (file)
@@ -1,28 +1,35 @@
 <?php
 class Maps {
 
-       public static function img($longitude,$latitude,$o=[]) {
+       public static function img($latitude,$longitude,$o=[]) {
                if (empty($o['width'])) $o['width'] = 72;
                if (empty($o['height'])) $o['height'] = 36;
                if (empty($o['zoom'])) $o['zoom'] = 10;
                $o['sensor'] = empty($o['sensor']) ? 'false' : 'true';
 
-               return 'http://maps.google.com/maps/api/staticmap?center='.$longitude.','.$latitude
+               return 'http://maps.google.com/maps/api/staticmap?center='.$latitude.','.$longitude
                        .( empty($o['zoom']) ? '' : '&zoom='.$o['zoom'])
                        .'&size='.$o['width'].'x'.$o['height']
                        .'&sensor='.$o['sensor']
                ;
        }
 
-       public static function link($longitude,$latitude) {
-               return $_SERVER['REQUEST_SCHEME'].'://maps.google.com/?q='.$longitude.','.$latitude;
+       public static function link($latitude,$longitude) {
+               return $_SERVER['REQUEST_SCHEME'].'://maps.google.com/?q='.$latitude.','.$longitude;
        }
 
-       public static function html(&$r) {
+       public static function row(&$r) {
                if (empty($r['latitude'])) return;
                if (empty($r['longitude'])) return;
-               $r['maps'] = '<a href="'.Maps::link($r['latitude'],$r['latitude']).'">'
-                       .'<img src="'.Maps::img($r['latitude'],$r['latitude']).'" />'
+               $r['maps'] = Maps::html($r['latitude'],$r['longitude']);
+               unset($r['latitude'],$r['longitude']);
+       }
+
+       public static function html($latitude,$longitude) {
+               if (empty($latitude)) return;
+               if (empty($longitude)) return;
+               return '<a href="'.Maps::link($latitude,$longitude).'">'
+                       .'<img src="'.Maps::img($latitude,$longitude).'" />'
                .'</a>';
        }