showmap.php 3.45 KB
Newer Older
dmorley's avatar
mapview  
dmorley committed
1
<?php
noplanman's avatar
noplanman committed
2 3 4 5 6

use RedBeanPHP\R;

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

dmorley's avatar
dmorley committed
7 8
require_once __DIR__ . '/config.php';

noplanman's avatar
noplanman committed
9 10 11 12 13 14 15
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 != ''
dmorley's avatar
dmorley committed
16 17
      AND status < ?
  ", [PodStatus::Recheck]);
noplanman's avatar
noplanman committed
18 19 20
} catch (\RedBeanPHP\RedException $e) {
  die('Error in SQL query: ' . $e->getMessage());
}
21

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

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

48
        $feat = '';
noplanman's avatar
noplanman committed
49 50 51 52 53
        $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
54

noplanman's avatar
noplanman committed
55 56
        $pod_name = htmlentities($pod['name'], ENT_QUOTES);
        $signup = $pod['signup'] ? 'yes' : 'no';
57
        echo <<<EOF
noplanman's avatar
noplanman committed
58 59 60 61
{
  'type': 'Feature',
  'id': '1',
  'properties' : {
noplanman's avatar
noplanman committed
62
    '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
63 64 65
  },
  'geometry': {
    'type': 'Point',
noplanman's avatar
noplanman committed
66
    'coordinates': [{$pod['long']},{$pod['lat']}]
noplanman's avatar
noplanman committed
67
  }
noplanman's avatar
noplanman committed
68
}
dmorley's avatar
dmorley committed
69
EOF;
70 71 72 73
      }
      ?>
    ]
  };
dmorley's avatar
dmorley committed
74
  var tiles = L.tileLayer('https://{s}.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.jpg70?access_token=<?php echo $mapboxkey; ?>', {
75 76 77
    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
78
  var map = L.map('map', {zoom: 4, center: [<?php echo $lat; ?>, <?php echo $long; ?>]}).addLayer(tiles);
79 80 81 82 83 84 85 86 87 88 89 90
  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
91
</script>