showmap.php 3.41 KB
Newer Older
dmorley's avatar
mapview  
dmorley committed
1
<?php
noplanman's avatar
noplanman committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

use RedBeanPHP\R;

defined('PODUPTIME') || die();

try {
  $pods = R::getAll("
    SELECT domain, signup, name, lat, long, softwarename, uptime_alltime, active_users_halfyear, service_facebook, service_twitter, service_tumblr, service_wordpress, service_xmpp
    FROM pods
    WHERE NOT hidden
      AND lat != ''
      AND long != ''
  ");
} catch (\RedBeanPHP\RedException $e) {
  die('Error in SQL query: ' . $e->getMessage());
}
18

dmorley's avatar
mapview  
dmorley committed
19 20
$csv = array_map('str_getcsv', file('db/country_latlon.csv'));
foreach ($csv as $cords) {
noplanman's avatar
noplanman committed
21
  if ($cords[0] === $country_code) {
22
    $lat  = $cords[1];
dmorley's avatar
dmorley committed
23
    $long = $cords[2];
dmorley's avatar
dmorley committed
24 25 26
  } else {
    $lat = 31;
    $long = -99;
dmorley's avatar
dmorley committed
27
  }
dmorley's avatar
mapview  
dmorley committed
28
}
dmorley's avatar
dmorley committed
29
?>
30
<link rel="stylesheet" href="bower_components/leaflet/dist/leaflet.css"/>
David Morley's avatar
David Morley committed
31 32
<script src="bower_components/leaflet/dist/leaflet.js"></script>
<script type="text/javascript" src="bower_components/leaflet.markercluster/dist/leaflet.markercluster.js"></script>
dmorley's avatar
dmorley committed
33 34
<div id="map"></div>
<script type="text/javascript">
35 36 37 38
  var geoJsonData = {
    'type': 'FeatureCollection',
    'features': [
      <?php
noplanman's avatar
noplanman committed
39 40

      $i = 0;
noplanman's avatar
noplanman committed
41
      foreach ($pods as $pod) {
noplanman's avatar
noplanman committed
42 43 44
        // If this isn't the first entry, put a comma to separate the entries.
        $i++ > 0 && print ',';

45
        $feat = '';
noplanman's avatar
noplanman committed
46 47 48 49 50
        $pod['service_facebook'] && $feat .= '<div class="smlogo smlogo-facebook" title="Publish to Facebook"></div>';
        $pod['service_twitter'] && $feat .= '<div class="smlogo smlogo-twitter" title="Publish to Twitter"></div>';
        $pod['service_tumblr'] && $feat .= '<div class="smlogo smlogo-tumblr" title="Publish to Tumblr"></div>';
        $pod['service_wordpress'] && $feat .= '<div class="smlogo smlogo-wordpress" title="Publish to WordPress"></div>';
        $pod['service_xmpp'] && $feat .= '<div class="smlogo smlogo-xmpp"><img src="/images/icon-xmpp.png" width="16" height="16" title="XMPP chat server" alt="XMPP chat server"></div>';
noplanman's avatar
noplanman committed
51

noplanman's avatar
noplanman committed
52 53
        $pod_name = htmlentities($pod['name'], ENT_QUOTES);
        $signup = $pod['signup'] ? 'yes' : 'no';
54
        echo <<<EOF
noplanman's avatar
noplanman committed
55 56 57 58
{
  'type': 'Feature',
  'id': '1',
  'properties' : {
noplanman's avatar
noplanman committed
59
    'html': '<a href="/go.php?domain={$pod['domain']}">{$pod_name}</a><br>Software: {$pod['softwarename']}<br> Open Signup: {$signup}<br> Users: {$pod['active_users_halfyear']}<br> Uptime: {$pod['uptime_alltime']}%<br> Services:{$feat}'
noplanman's avatar
noplanman committed
60 61 62
  },
  'geometry': {
    'type': 'Point',
noplanman's avatar
noplanman committed
63
    'coordinates': [{$pod['long']},{$pod['lat']}]
noplanman's avatar
noplanman committed
64
  }
noplanman's avatar
noplanman committed
65
}
dmorley's avatar
dmorley committed
66
EOF;
67 68 69 70 71 72 73 74
      }
      ?>
    ]
  };
  var tiles = L.tileLayer('https://{s}.tiles.mapbox.com/v4/diasporg.l615e519/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZGlhc3BvcmciLCJhIjoibTVBaldtayJ9.HdGPBIFeZyNKKQqCmU11nA', {
    maxZoom: 18,
    attribution: '<a href="https://www.mapbox.com/about/maps/" target="_blank">&copy; Mapbox &copy; OpenStreetMap</a> <a class="mapbox-improve-map" href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a>'
  });
dmorley's avatar
dmorley committed
75
  var map = L.map('map', {zoom: 3, center: [<?php echo $lat; ?>, <?php echo $long; ?>]}).addLayer(tiles);
76 77 78 79 80 81 82 83 84 85 86 87
  var markers = L.markerClusterGroup({
    maxClusterRadius: 2, animateAddingMarkers: true, iconCreateFunction: function (cluster) {
      return new L.DivIcon({html: '<b class="icon">' + cluster.getChildCount() + '</b>', className: 'mycluster', iconSize: L.point(35, 35)});
    }
  });
  var geoJsonLayer = L.geoJson(geoJsonData, {
    onEachFeature: function (feature, layer) {
      layer.bindPopup(feature.properties.html);
    }
  });
  markers.addLayer(geoJsonLayer);
  map.addLayer(markers);
dmorley's avatar
mapview  
dmorley committed
88
</script>