zeg1jeux/map.php

281 lines
5.5 KiB
PHP

<?php
require_once('config.php');
require_once('lib/Gchange.class.php');
require_once('lib/Location.class.php');
if (!isset($_SESSION['player_pubkey'])) {
header('Location: index.php');
}
$bodyIds = 'sonar';
include_once('header.php');
$gchange = new Gchange();
$player = $gchange->getUser($_SESSION['player_pubkey']);
$origLat = $player->_source->geoPoint->lat;
$origLon = $player->_source->geoPoint->lon;
$origLoc = new Location();
$origLoc->setPosition($origLat, $origLon);
echo '
<section id="mapview">
<aside id="geoPoint">
<a href=".">'. $origLat . ' , ' . $origLon .'</a>
</aside>
<div
id="map"
data-orig-lat="'. $origLat .'"
data-orig-lon="'. $origLon .'"
data-radius="'. $_SESSION['radius'] .'"
>
<div id="map-deco"></div>
<section class="player" style="left: calc(50% - '. DEMI_TAILLE_SPRITE . 'px); top: calc(50% - '. DEMI_TAILLE_SPRITE . 'px);">';
if (isset($player->_source->avatar->_content) and !empty($player->_source->avatar->_content)) {
$src = 'data:'. $player->_source->avatar->_content_type .';base64,' . $player->_source->avatar->_content;
} else {
$src = 'assets/img/avatars/32/et-in-flying-saucer.png.png';
}
echo '
<img src="'. $src . '"
alt="'. $player->_source->title .'"
width="'. TAILLE_SPRITE .'"
height="'. TAILLE_SPRITE .'" />
</section>
';
$places = $gchange->getPlacesNearUser($player, $_SESSION['radius']);
$selectedPlace = NULL;
foreach ($places as $place) {
if (isset($_GET['place']) and ($place->_id == $_GET['place'])) {
$selectedPlace = $place;
}
$placeLat = $place->_source->geoPoint->lat;
$placeLon = $place->_source->geoPoint->lon;
echo '
<section class="place"
id="place-'. $place->_id .'"
data-place-lat="'. $placeLat .'"
data-place-lon="'. $placeLon .'"
>';
echo '
<a href="?place='. $place->_id .'">';
if (isset($place->_source->avatar->_content) and !empty($place->_source->avatar->_content)) {
$src = 'data:'. $place->_source->avatar->_content_type .';base64,' . $place->_source->avatar->_content;
} else {
$src = 'assets/img/yourte.png';
}
echo '
<img src="'. $src .'"
alt="'. $place->_source->title . '"
title="'. $place->_source->title .'"
width="'. TAILLE_SPRITE .'"
height="'. TAILLE_SPRITE .'" />';
echo '
</a>
<article>';
echo '
</article>
</section>';
}
echo '
</div>
</section>';
if (isset($selectedPlace)) {
echo '
<aside id="place-details">';
$place = $selectedPlace;
$placeLat = $place->_source->geoPoint->lat;
$placeLon = $place->_source->geoPoint->lon;
$placeLoc = new Location();
$placeLoc->setPosition($placeLat, $placeLon);
echo '
<h3 class="place-name">
'. $place->_source->title . '
</h3>';
echo '
<address>
<p class="position">
'. $placeLat . ',' . $placeLon .'
</p>
<p class="distance">
à '. ceil(Location::geoDist($origLoc, $placeLoc)) .'km
</p>
</address>
<p class="get-directions">
Y aller&nbsp;:
<a class="car" href="https://www.google.com/maps/dir/'. $origLat .','. $origLon .'/'.$placeLat .','. $placeLon .'/data=!3m1!4b1!4m2!4m1!3e0">
<span>
en voiture
</span>
</a>,
<a class="bike" href="https://www.google.com/maps/dir/'. $origLat .','. $origLon .'/'.$placeLat .','. $placeLon .'/data=!3m1!4b1!4m2!4m1!3e1">
<span>
en vélo
</span>
</a>,
<br />
<a class="foot" href="https://www.google.com/maps/dir/'. $origLat .','. $origLon .'/'.$placeLat .','. $placeLon .'/data=!3m1!4b1!4m2!4m1!3e2">
<span>
à pied
</span>
</a>
</p>
';
$records = $gchange->getRecordsByIssuer($place->_source->issuer);
$offers = [];
$needs = [];
$crowdfundings = [];
foreach ($records as $record) {
switch ($record->_source->type) {
case 'offer':
$offers[] = $record;
break;
case 'need':
$needs[] = $record;
break;
case 'crowdfunding':
$crowdfundings[] = $record;
break;
}
}
if (!empty($needs)) {
echo '<h4>Demandes</h4>';
echo '<ul>';
foreach ($needs as $item) {
$description = isset($item->_source->description) ? ' title="'. substr($item->_source->description, 0, 30) . '"' : '';
echo '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->_id . '/"'. $description .'>
' . $item->_source->title . '
</a>
</li>
';
}
echo '</ul>';
}
if (!empty($offers)) {
echo '<h4>Offres</h4>';
echo '<ul>';
foreach ($offers as $item) {
$description = isset($item->_source->description) ? ' title="'. substr($item->_source->description, 0, 30) . '"' : '';
echo '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->_id . '/"'. $description .'>
' . $item->_source->title . '
</a>
</li>
';
}
echo '</ul>';
}
if (!empty($crowdfundings)) {
echo '<h4>Financements participatifs</h4>';
echo '<ul>';
foreach ($crowdfundings as $item) {
$description = isset($item->description) ? ' title="'. substr($item->_source->description, 0, 30) . '"' : '';
echo '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->_id . '/"'. $description .'>
' . $item->_source->title . '
</a>
</li>
';
}
echo '</ul>';
}
if (isset($place->_source->description) and !empty($place->_source->description)) {
echo '
<h4>À propos du lieu</h4>
<p class="place-desc">
'. $place->_source->description . '
</p>';
}
echo '
</aside>';
}
include_once('footer.php');