zeg1jeux/map.php

386 lines
7.4 KiB
PHP

<?php
require_once('config.php');
require_once('lib/Gchange.class.php');
require_once('lib/Location.class.php');
require_once('lib/ErrorsHandler.class.php');
if (!isset($_SESSION['player_pubkey'])) {
header('Location: index.php');
}
if (isset($_GET['r']) and in_array($_GET['r'], $radiuses)) {
$_SESSION['radius'] = $_GET['r'];
}
function getThemeScriptsFullPath ($themeScript) {
return GAME_JS_DIR . '/' . $themeScript;
}
$gameScripts = array_map('getThemeScriptsFullPath', array_slice(scandir(GAME_JS_DIR), 2));
$javascripts['footer'] = array_merge($javascripts['footer'], $gameScripts);
$bodyIds = 'sonar';
include_once('header.php');
$gchange = new Gchange();
$player = $gchange->getUser($_SESSION['player_pubkey']);
// die('<pre>' . print_r($player, true) . '</pre>');
$origLat = $player->getLat();
$origLon = $player->getLon();
$origLoc = new Location();
$origLoc->setPosition($origLat, $origLon);
echo '
<nav id="go-back-home">
<a href="home.php">
<span>
Retour au tableau de bord
</span>
</a>
</nav>
<section id="mapview">
<aside id="geoPoint">
<span id="origLat">'.
$origLat .
'</span><span class="sep">,</span><span id="origLon">' .
$origLon .
'</span>
</aside>
<nav id="zoom">
';
foreach ($radiuses as $r) {
echo '
<a href="?r='. $r .'">
'. $r . 'km
</a>';
}
echo '
</nav>
<div
id="map"
data-orig-lat="'. $origLat .'"
data-orig-lon="'. $origLon .'"
data-radius="'. $_SESSION['radius'] .'"
>
<div id="map-deco"></div>
';
/*
echo '
<section class="player" style="left: calc(50% - '. DEMI_TAILLE_SPRITE . 'px); top: calc(50% - '. DEMI_TAILLE_SPRITE . 'px);">';
$avatarSrc = $player->getAvatarImgSrc();
$src = !empty($avatarSrc) ? $avatarSrc : $games[$_SESSION['gameId']]['default_avatar'];
echo '
<img src="'. $src . '"
alt="'. $player->getUserName() .'"
title="'. $player->getUserName() .'"
width="'. TAILLE_SPRITE .'"
height="'. TAILLE_SPRITE .'" />
</section>
';
*/
$places = $gchange->getPlacesNearUser($player, $_SESSION['radius'], MAX_NEARBY_PLACES);
$selectedPlace = NULL;
foreach ($places as $place) {
$placeLat = $place->_source->geoPoint->lat;
$placeLon = $place->_source->geoPoint->lon;
echo '
<section class="place"
id="place-'. $place->_id .'"
data-place-name="'. $place->_source->title .'"
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>';
if (isset($_GET['place']) and ($place->_id == $_GET['place'])) {
$selectedPlace = $place;
}
}
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_visitors = [];
$records_placeCreator = [];
try {
$records_placeCreator = $gchange->getRecordsByIssuer($place->_source->issuer);
} catch (Exception $errorMsgs) {
// Pas d'annonce pour le créateur du lieu
}
try {
$visitors = $gchange->getUsersInDaPlace($place->_id);
if (!empty($visitors)) {
echo '
<h4>Visiteurs</h4>
<ul class="visitors">';
foreach ($visitors as $visitor) {
try {
$records_visitor = $gchange->getRecordsByIssuer($visitor->getUserGchangeId());
$records_visitors = array_merge($records_visitors, $records_visitor);
echo '
<li class="visitor">';
$avatarSrc = $visitor->getAvatarImgSrc();
$src = !empty($avatarSrc) ? $avatarSrc : $games[$_SESSION['gameId']]['default_avatar'];
echo '
<img src="'. $src . '"
alt="'. $visitor->getUserName() .'"
title="'. $visitor->getUserName() .'"
width="64"
height="64" />
</li>';
} catch (Exception $errorMsgs) {
// Pas d'annonce pour cet utilisateur
}
}
echo '
</ul>';
}
} catch (Exception $errorMsgs) {
// Visiteurs trouvés nulle part
}
$records = array_merge($records_placeCreator, $records_visitors);
$offers = [];
$needs = [];
$crowdfundings = [];
foreach ($records as $record) {
switch ($record->getType()) {
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 = !empty($item->getDescription()) ? ' title="'. substr($item->getDescription(), 0, 30) . '"' : '';
echo '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->getGchangeId() . '/"'. $description .'>
' . $item->getTitle() . '
</a>
</li>
';
}
echo '</ul>';
}
if (!empty($offers)) {
echo '<h4>Offres</h4>';
echo '<ul>';
foreach ($offers as $item) {
$description = !empty($item->getDescription()) ? ' title="'. substr($item->getDescription(), 0, 30) . '"' : '';
echo '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->getGchangeId() . '/"'. $description .'>
' . $item->getTitle() . '
</a>
</li>
';
}
echo '</ul>';
}
if (!empty($crowdfundings)) {
echo '<h4>Financements participatifs</h4>';
echo '<ul>';
foreach ($crowdfundings as $item) {
$description = !empty($item->getDescription()) ? ' title="'. substr($item->getDescription(), 0, 30) . '"' : '';
echo '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->getGchangeId() . '/"'. $description .'>
' . $item->getTitle() . '
</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');