gMaville/mytown.php

252 lines
5.1 KiB
PHP

<?php
require_once('config.php');
require_once('lib/Gchange.class.php');
require_once('lib/CesiumPlus.class.php');
require_once('lib/Location.class.php');
$gchange = new Gchange();
$cesiumPlus = new CesiumPlus();
if (isset($_GET['location'])) {
$_SESSION['location'] = $_GET['location'];
if ($userPos = Location::createFromAddress($_GET['location'])) {
$_SESSION['lat'] = $userPos->getLat();
$_SESSION['lon'] = $userPos->getLon();
$_SESSION['location'] = htmlspecialchars($_GET['location']);
}
}
if (isset($_SESSION['lat'], $_SESSION['lon'])) {
$userPos = new Location();
$userPos->setPosition($_SESSION['lat'], $_SESSION['lon']);
}
include('header.php');
echo '<h2>Événements à '. EVENT_RADIUS .' km autour de '. $_SESSION['location'] . '</h2>';
$feedUrl = sprintf(CALENDAR_1_LOCAL_FEED, EVENT_RADIUS, $_SESSION['lat'], $_SESSION['lon']);
$content = @file_get_contents($feedUrl);
if (!empty($content)) {
$x = new SimpleXmlElement($content);
echo '
<p>
Événements importés automatiquement depuis
<a href="'. htmlspecialchars(CALENDAR_1_URL) .'">
l\'Agenda du libre
</a>&nbsp;:
</p>';
echo '<ul>';
foreach($x->item as $entry) {
echo '
<li>
<a href="'. $entry->link .'"
title="'. substr(strip_tags($entry->description), 0, 60) . '">
'. $entry->title . '
</a>
</li>';
}
echo '</ul>';
}
echo '
<p>
Événements importés automatiquement depuis
<a href="'. CALENDAR_2_URL .'">
forum.monnaie-libre.fr
</a>&nbsp;:
</p>';
$content = @file_get_contents(CALENDAR_2_FEED);
$x = json_decode($content);
echo '<ul>';
$i = 0;
$limit = 20;
$todayIso = new DateTime();
foreach($x->topic_list->topics as $entry) {
$eventLoc = NULL;
$eventDate = new DateTime($entry->event->start);
if ($eventDate >= $todayIso) {
if (isset($entry->location->geo_location->lat, $entry->location->geo_location->lon)) {
$eventLoc = new Location();
$eventLoc->setPosition($entry->location->geo_location->lat, $entry->location->geo_location->lon);
} else {
$searchTerms = [];
if (isset($entry->location->geo_location->country)) {
$searchTerms[] = $entry->location->geo_location->country;
}
if (isset($entry->location->geo_location->state)) {
$searchTerms[] = $entry->location->geo_location->state;
}
if (isset($entry->location->geo_location->postalcode)) {
$searchTerms[] = $entry->location->geo_location->postalcode;
}
if (isset($entry->location->geo_location->city)) {
$searchTerms[] = $entry->location->geo_location->city;
}
if (isset($entry->location->geo_location->address)) {
$searchTerms[] = $entry->location->geo_location->address;
}
if (!empty($searchTerms)) {
$eventLoc = Location::createFromAddress($searchTerms);
}
}
if (isset($eventLoc) and $eventLoc and (($dist = Location::geoDist($eventLoc->getPosition(), $userPos->getPosition())) <= EVENT_RADIUS)) {
echo '
<li>[à ' . round($dist) . '&nbsp;km] ';
if (isset($eventDate)) {
echo '
, le '. $eventDate->format('j ') . moisFr($eventDate->format('n')) . $eventDate->format(' Y');
}
echo '&nbsp;:
<a href="'. sprintf(CALENDAR_2_EVENT_URL, $entry->id) .'"
title="'. substr(strip_tags($entry->excerpt), 0, 60) . '">
'. $entry->title . '
</a>';
if (isset($entry->location->geo_location->city)) {
echo '
, à '. $entry->location->geo_location->city;
}
echo '
</li>';
++$i;
if ($i == $limit) {
break;
}
}
}
}
echo '</ul>';
echo '<h2>Contacter d\'autres junistes près de '. $_SESSION['location'] . '</h2>';
echo '
<p>
Consulter la doc de OpenStreetMap API pour voir comment récupérer les descriptions des pins des groupes locaux de la Framacarte.
</p>';
echo '
<p>
<a href="'. BB_URL . '">
Groupe de discussion par mail du groupe de Vannes
</a>
</p>';
$offers = $gchange->getNearbyOffers($_SESSION['lat'], $_SESSION['lon'], RADIUS);
echo '<h2>Annonces à '. RADIUS . ' km autour de '. $_SESSION['location'] .'</h2>';
echo '<ol>';
foreach ($offers as $offer) {
$description = isset($offer->_source->description) ? ' title="'. substr($offer->_source->description, 0, 30) . '"' : '';
echo '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $offer->_id . '/"'. $description .'>
' . $offer->_source->title . '
</a>
('. $offer->_source->city . ')
</li>
';
}
echo '</ol>';
$users = $cesiumPlus->getNearbyUsers($_SESSION['lat'], $_SESSION['lon'], RADIUS);
echo '<h2>Nouveaux utilisateurs à '. RADIUS . ' km autour de '. $_SESSION['location'] .'</h2>';
echo '<table>';
foreach ($users as $user) {
$date = new DateTime();
$date->setTimestamp($user->_source->time);
echo '
<tr>
<td class="date">'. $date->format('j') . ' ' . moisFr($date->format('n')) . ' ' . $date->format('Y') . '</td>
<td>
<a href="https://demo.cesium.app/#/app/wot/'. $user->_source->issuer . '/">
' . $user->_source->title . '
</a>
</td>
</tr>
';
}
echo '</table>';
include('footer.php');