La Bureautique vaincra.
@ -0,0 +1,2 @@
|
||||
cache/
|
||||
tests/
|
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 1.6 KiB |
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
|
||||
session_start();
|
||||
|
||||
define('DEFAULT_RADIUS', 50);
|
||||
|
||||
define('TAILLE_SPRITE', 32);
|
||||
define('DEMI_TAILLE_SPRITE', (TAILLE_SPRITE/2));
|
||||
|
||||
define('SONAR_DURATION', 5);
|
||||
|
||||
define("LAT_ASTROPORT_ONE", 44.22484418236386);
|
||||
define("LON_ASTROPORT_ONE", 1.6395813014177014);
|
||||
|
||||
class Player {
|
||||
|
||||
private $pubkey;
|
||||
|
||||
private $name;
|
||||
|
||||
function __construct ($pubkey, $name) {
|
||||
|
||||
$this->pubkey = $pubkey;
|
||||
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
function getPubkey () {
|
||||
|
||||
return $this->pubkey;
|
||||
}
|
||||
|
||||
function getName () {
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
|
||||
$players = [
|
||||
|
||||
new Player('2L8vaYixCf97DMT8SistvQFeBj7vb6RQL7tvwyiv1XVH', 'Fred'),
|
||||
new Player('25zB1gSC7Qhwnx463cuDLDCKLRVieLAgFiPbYq6jVHG9', 'Boris'),
|
||||
new Player('u3rNW7CzqDC5V4L3FGVbSPsrBd78y8pkRACKHtBtCPx', 'Syoul'),
|
||||
new Player('8PTThXiUSwwuPoqQWw3tuAn4MpvzQzpKhs6LMuiozS7Z', 'kimamila')
|
||||
];
|
||||
|
||||
|
||||
if (!isset($_SESSION['radius'])) {
|
||||
|
||||
$_SESSION['radius'] = DEFAULT_RADIUS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
=====================
|
||||
Games
|
||||
=====================
|
||||
|
||||
*/
|
||||
|
||||
$games = [
|
||||
|
||||
'spationaute' => [
|
||||
|
||||
'title' => 'SpaceĞ1',
|
||||
'description' => 'Les extraterrestres viennent terraformer ta planète'
|
||||
],
|
||||
|
||||
'magie' => [
|
||||
|
||||
'title' => 'Ğ1Quest',
|
||||
'description' => 'Ğarry Potier à l\'école des sourciers.'
|
||||
]
|
||||
];
|
||||
|
||||
define('DEFAULT_GAME', 'spationaute');
|
||||
|
||||
if (!isset($_SESSION['gameId'])) {
|
||||
|
||||
$_SESSION['gameId'] = DEFAULT_GAME;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
require_once('functions.php');
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
function moisFr ($n) {
|
||||
|
||||
switch ($n) {
|
||||
|
||||
case 1:
|
||||
return "janvier";
|
||||
case 2:
|
||||
return "février";
|
||||
case 3:
|
||||
return "mars";
|
||||
case 4:
|
||||
return "avril";
|
||||
case 5:
|
||||
return "mai";
|
||||
case 6:
|
||||
return "juin";
|
||||
case 7:
|
||||
return "juillet";
|
||||
case 8:
|
||||
return "août";
|
||||
case 9:
|
||||
return "septembre";
|
||||
case 10:
|
||||
return "octobre";
|
||||
case 11:
|
||||
return "novembre";
|
||||
case 12:
|
||||
return "décembre";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Geoloc</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<body>
|
||||
|
||||
|
||||
<button onclick="getLocation()">Me géolocaliser</button>
|
||||
|
||||
<p id="result">
|
||||
</p>
|
||||
|
||||
<script>
|
||||
|
||||
var result = document.getElementById('result');
|
||||
|
||||
function getLocation() {
|
||||
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(showPosition);
|
||||
} else {
|
||||
result.innerHTML = "Geolocation is not supported by this browser.";
|
||||
}
|
||||
}
|
||||
|
||||
function showPosition(position) {
|
||||
|
||||
result.innerHTML = "Latitude: " + position.coords.latitude +
|
||||
"<br>Longitude: " + position.coords.longitude;
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>La bureautique</title>
|
||||
<?php
|
||||
echo '
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="themes/'. $_SESSION['gameId'] .'/layout.css" />
|
||||
<link rel="stylesheet" type="text/css" href="themes/'. $_SESSION['gameId'] .'/deco.css" />
|
||||
|
||||
';
|
||||
?>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
</head>
|
||||
<?php
|
||||
$bodyIds = !isset($bodyIds) ? '' : ' id="'. $bodyIds .'"';
|
||||
?>
|
||||
<body<?php echo $bodyIds; ?>>
|
||||
|
||||
<!--
|
||||
<h1>La bureautique</h1>
|
||||
-->
|
||||
|
||||
<main>
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
require_once('DAO.class.php');
|
||||
|
||||
class CesiumPlus {
|
||||
|
||||
private $dao;
|
||||
|
||||
public function __construct () {
|
||||
|
||||
$this->dao = DAO::getInstance();
|
||||
}
|
||||
|
||||
public function getNearbyUsers ($lat, $lon, $radius) {
|
||||
|
||||
$n = 15;
|
||||
|
||||
$queryParams = [
|
||||
'size' => $n,
|
||||
|
||||
'query' => [
|
||||
'bool' => [
|
||||
'must' => [
|
||||
[
|
||||
'geo_distance' => [
|
||||
|
||||
"distance" => $radius . 'km',
|
||||
"geoPoint"=> [
|
||||
"lat" => $lat,
|
||||
"lon" => $lon
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
"sort" => [
|
||||
[ "time" => ["order" => "desc"] ],
|
||||
"_score"
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
$json = $this->dao->fetchJson('/user/profile/_search?pretty', 'gchange', $queryParams);
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result->hits->hits;
|
||||
}
|
||||
}
|
@ -0,0 +1,588 @@
|
||||
<?php
|
||||
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
|
||||
class DAO {
|
||||
|
||||
/**********************
|
||||
* Constants
|
||||
**********************/
|
||||
|
||||
const PUBKEY_FORMAT = '#^[a-zA-Z1-9]{43,44}$#';
|
||||
|
||||
const DATE_FORMAT = 'Y-m-d';
|
||||
|
||||
private $units = ['quantitative','relative'];
|
||||
|
||||
private $truePossibleValues = ['true','1', 'yes'];
|
||||
|
||||
private $qrCodesFolder = __DIR__ . '/img/qrcodes';
|
||||
|
||||
private $qrCodePath = NULL;
|
||||
|
||||
private $logosFolder = __DIR__ . '/img/logos';
|
||||
|
||||
private $logo = NULL;
|
||||
|
||||
private $logoPath = NULL;
|
||||
|
||||
private $validDisplayTypes = ['img', 'svg', 'html'];
|
||||
|
||||
private $cacheDir = __DIR__ . '/../cache/';
|
||||
|
||||
private $isActivatedCache = true;
|
||||
|
||||
private $cacheLongevity = 10800; // in seconds
|
||||
|
||||
public static $dao;
|
||||
|
||||
/**********************
|
||||
* General parameters
|
||||
**********************/
|
||||
|
||||
private $pubkey;
|
||||
|
||||
private $nodes = [
|
||||
|
||||
'gchange' => [
|
||||
|
||||
'data.gchange.fr'
|
||||
],
|
||||
|
||||
'cesiumplus' => [
|
||||
|
||||
'g1.data.le-sou.org',
|
||||
'g1.data.duniter.fr'
|
||||
],
|
||||
|
||||
'duniter' => [
|
||||
|
||||
'duniter.g1.1000i100.fr',
|
||||
'duniter-g1.p2p.legal',
|
||||
'duniter.normandie-libre.fr',
|
||||
'g1.mithril.re',
|
||||
'g1.presles.fr',
|
||||
'duniter.vincentux.fr',
|
||||
'g1.le-sou.org',
|
||||
'g1.donnadieu.fr',
|
||||
]
|
||||
];
|
||||
|
||||
private $nodeTimeout = [
|
||||
|
||||
'duniter' => 2,
|
||||
'cesiumplus' => 5,
|
||||
'gchange' => 5,
|
||||
];
|
||||
|
||||
private $nodeTimeoutIncrement = [
|
||||
|
||||
'duniter' => 2,
|
||||
'cesiumplus' => 10,
|
||||
'gchange' => 10
|
||||
];
|
||||
|
||||
private $node = NULL;
|
||||
|
||||
private $unit = 'quantitative';
|
||||
|
||||
|
||||
/**********************
|
||||
* Methods
|
||||
**********************/
|
||||
|
||||
public function __construct () {
|
||||
|
||||
}
|
||||
|
||||
public static function getInstance () {
|
||||
|
||||
if (!isset(DAO::$dao)) {
|
||||
|
||||
DAO::$dao = new DAO();
|
||||
}
|
||||
|
||||
return DAO::$dao;
|
||||
}
|
||||
|
||||
private function setUnit ($unit) {
|
||||
|
||||
if (!empty($unit)) {
|
||||
|
||||
if (!in_array($unit, $this->units)) {
|
||||
|
||||
$out = [];
|
||||
$out[] = _('L\'unité renseignée n\'existe pas.');
|
||||
$out[] = _('Vérifiez votre synthaxe.');
|
||||
|
||||
$this->decease($out);
|
||||
|
||||
} else {
|
||||
|
||||
$this->unit = $unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function decease ($errorMsgs) {
|
||||
|
||||
if (!is_array($errorMsgs)) {
|
||||
|
||||
$errorMsgs = explode("\n", $errorMsgs);
|
||||
}
|
||||
|
||||
|
||||
if ($this->displayType == 'img') {
|
||||
|
||||
$source = imagecreatetruecolor(500, 200);
|
||||
|
||||
$bgColor = imagecolorallocate($source,
|
||||
255, 255, 255);
|
||||
|
||||
imagefill($source,
|
||||
0, 0,
|
||||
$bgColor);
|
||||
|
||||
$txtColor = imagecolorallocate($source,
|
||||
0, 0, 0);
|
||||
|
||||
$errorMsgFontSize = 3;
|
||||
$x = 5;
|
||||
$y = 5;
|
||||
|
||||
foreach ($errorMsgs as $msg) {
|
||||
|
||||
imagestring($source, $errorMsgFontSize, $x, $y, utf8_decode($msg), $txtColor);
|
||||
|
||||
$y += $errorMsgFontSize + 20;
|
||||
}
|
||||
|
||||
|
||||
imagepng($source);
|
||||
imagedestroy($source);
|
||||
|
||||
} else if ($this->displayType == 'svg') {
|
||||
|
||||
echo '<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg width="580"
|
||||
height="224"
|
||||
style="fill:black;"
|
||||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<g style="font-family:sans-serif;">';
|
||||
|
||||
$x = 25;
|
||||
$y = 25;
|
||||
|
||||
foreach ($errorMsgs as $msg) {
|
||||
|
||||
echo '
|
||||
<text
|
||||
style="font-size:.8rem;"
|
||||
x="'. $x .'"
|
||||
y="'. $y . '"
|
||||
dominant-baseline="hanging">
|
||||
'. $msg . '
|
||||
</text>';
|
||||
|
||||
$y += 25;
|
||||
}
|
||||
|
||||
echo '
|
||||
</g>
|
||||
</svg>';
|
||||
|
||||
} else {
|
||||
|
||||
ob_get_clean(); // to prevent error message to display inside an HTML container (case of error generated by get method calls)
|
||||
|
||||
echo '<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>'. _('Erreur critique') . '</title>
|
||||
|
||||
<style>
|
||||
|
||||
div {
|
||||
|
||||
overflow: auto;
|
||||
word-wrap: break-word;
|
||||
background-color: hsl(0, 100%, 69%);
|
||||
color: hsl(0, 100%, 19%);
|
||||
margin: 1em;
|
||||
padding: 1em;
|
||||
border-radius: 1em;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: calc(100% - 4em);
|
||||
max-height: calc(100vh - 4em);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>';
|
||||
|
||||
|
||||
foreach ($errorMsgs as $msg) {
|
||||
|
||||
echo '<p>' . $msg . '</p>';
|
||||
}
|
||||
|
||||
echo '
|
||||
</div>
|
||||
</body>
|
||||
</html>';
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public function printUnit () {
|
||||
|
||||
if ($this->unit == 'relative') {
|
||||
|
||||
if ($this->displayType == 'img') {
|
||||
|
||||
return _('DUĞ1');
|
||||
|
||||
} else {
|
||||
|
||||
return _('DU<sub>Ğ1</sub>');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
return _('Ğ1');
|
||||
}
|
||||
}
|
||||
|
||||
public function convertIntoChosenUnit ($amountInQuantitative) {
|
||||
|
||||
if ($this->unit == 'quantitative') {
|
||||
|
||||
return $amountInQuantitative;
|
||||
|
||||
} else {
|
||||
|
||||
if (!isset($this->startDateUdAmount)) {
|
||||
|
||||
$this->startDateUdAmount = $this->getUdAmount($this->startDate);
|
||||
}
|
||||
|
||||
return round($amountInQuantitative / $this->startDateUdAmount, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function addNode ($node) {
|
||||
|
||||
$node = htmlspecialchars($node);
|
||||
|
||||
$this->nodes = array_unique(
|
||||
array_merge(
|
||||
(array)$node,
|
||||
$this->nodes
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function addNodes ($nodes) {
|
||||
|
||||
if (!is_array($nodes)) {
|
||||
|
||||
$nodes = explode(' ', $nodes);
|
||||
}
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
|
||||
$this->addNode($node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $nodes array
|
||||
*/
|
||||
public function getNodesList ($nodeType = 'duniter') {
|
||||
|
||||
switch ($nodeType) {
|
||||
|
||||
case 'gchange':
|
||||
$nodesFilename = 'nodes-gchange';
|
||||
break;
|
||||
case 'cesiumplus':
|
||||
$nodesFilename = 'nodes-cesiumplus';
|
||||
break;
|
||||
default:
|
||||
$nodesFilename = 'nodes';
|
||||
break;
|
||||
}
|
||||
|
||||
$nodesFilename .= '.txt';
|
||||
$nodesFullpath = $this->cacheDir . $nodesFilename;
|
||||
|
||||
$nodes = $this->nodes[$nodeType];
|
||||
|
||||
if ($this->isActivatedCache) {
|
||||
|
||||
if (!file_exists($nodesFullpath)) {
|
||||
|
||||
shuffle($nodes);
|
||||
|
||||
$this->cacheNodes($nodes, $nodeType);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
$nodesStr = file_get_contents($nodesFullpath);
|
||||
|
||||
$nodes = explode("\n", $nodesStr);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
shuffle($nodes);
|
||||
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
protected function cacheNodes ($nodes, $nodeType = 'duniter') {
|
||||
|
||||
switch ($nodeType) {
|
||||
|
||||
case 'gchange':
|
||||
$nodesFilename = 'nodes-gchange';
|
||||
break;
|
||||
case 'cesiumplus':
|
||||
$nodesFilename = 'nodes-cesiumplus';
|
||||
break;
|
||||
default:
|
||||
$nodesFilename = 'nodes';
|
||||
break;
|
||||
}
|
||||
$nodesFilename .= '.txt';
|
||||
|
||||
if (!file_exists($this->cacheDir)) {
|
||||
|
||||
mkdir($this->cacheDir, 0777, true);
|
||||
|
||||
}
|
||||
|
||||
file_put_contents($this->cacheDir . $nodesFilename, implode("\n", $nodes));
|
||||
}
|
||||
|
||||
protected function saveNodes ($nodes, $nodeType = 'duniter') {
|
||||
|
||||
$this->nodes[$nodeType] = $nodes;
|
||||
}
|
||||
|
||||
protected function fetchJson_aux ($nodes, $uri, $nodeType, $queryParams, $nodesNb, $nodeTimeout) {
|
||||
|
||||
// $header = 'Content-Type: application/x-www-form-urlencoded';
|
||||
// $header = "Content-Type: text/xml\r\n";
|
||||
|
||||
if (!empty($queryParams)) {
|
||||
|
||||
$opts = [
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'content' => json_encode($queryParams),
|
||||
// 'header' => $header,
|
||||
'timeout' => $nodeTimeout
|
||||
]
|
||||
];
|
||||
|
||||
} else {
|
||||
|
||||
$opts = [
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'timeout' => $nodeTimeout
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
$streamContext = stream_context_create($opts);
|
||||
|
||||
$i = 0;
|
||||
|
||||
do {
|
||||
|
||||
|
||||
$json = @file_get_contents("https://" . current($nodes) . $uri,
|
||||
false,
|
||||
$streamContext);
|
||||
|
||||
if (empty($json)) {
|
||||
|
||||
$nodes[] = array_shift($nodes);
|
||||
++$i;
|
||||
}
|
||||
|
||||
} while (empty($json) and ($i < $nodesNb));
|
||||
|
||||
if (!empty($json)) {
|
||||
|
||||
// Let's save node order for other queries :
|
||||
$this->saveNodes($nodes, $nodeType);
|
||||
|
||||
if ($this->isActivatedCache) {
|
||||
|
||||
$this->cacheNodes($nodes, $nodeType);
|
||||
}
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
|
||||
public function fetchJson ($uri, $nodeType = 'duniter', $queryParams = NULL) {
|
||||
|
||||
$json = NULL;
|
||||
|
||||
$nodes = $this->getNodesList($nodeType);
|
||||
|
||||
$nodesNb = count($nodes);
|
||||
|
||||
$maxTries = 3;
|
||||
|
||||
$nodeTimeout = $this->nodeTimeout[$nodeType];
|
||||
$nodeTimeoutIncrement = $this->nodeTimeoutIncrement[$nodeType];
|
||||
|
||||
for ($i = 0; ($i < 3) and empty($json); ++$i) {
|
||||
|
||||
$json = $this->fetchJson_aux($nodes, $uri, $nodeType, $queryParams, $nodesNb, $nodeTimeout);
|
||||
|
||||
$nodeTimeout += $nodeTimeoutIncrement;
|
||||
}
|
||||
|
||||
if (empty($json)) {
|
||||
|
||||
$out = [];
|
||||
$out[] = _('Aucun noeud '. $nodeType .' n\'a été trouvé ou la requête n\'a pas abouti.');
|
||||
$out[] = _('Noeud interrogés : ');
|
||||
|
||||
$out = array_merge($out, $nodes);
|
||||
|
||||
$out[] = _('URI: ' . $uri);
|
||||
|
||||
if (isset($queryParams)) {
|
||||
|
||||
$out[] = _('Paramètres de la requête : ');
|
||||
$out[] = print_r($queryParams, true);
|
||||
}
|
||||
|
||||
$this->decease($out);
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
protected function fetchUdAmount ($date) {
|
||||
|
||||
// On récupère les numéros de chaque blocks de DU journalier
|
||||
$json = $this->fetchJson('/blockchain/with/ud');
|
||||
$blocks = json_decode($json)->result->blocks;
|
||||
|
||||
if ($date > $this->now) {
|
||||
|
||||
// On récupère le dernier block
|
||||
$blockNum = end($blocks);
|
||||
|
||||
} else {
|
||||
|
||||
// On récupère le bloc de la date qui nous intéresse
|
||||
$blockNum = $blocks[count($blocks) - $this->today->diff($date)->format("%a") - 1];
|
||||
}
|
||||
|
||||
// Puis on récupère le montant du DU
|
||||
$json = $this->fetchJson('/blockchain/block/' . $blockNum);
|
||||
$block = json_decode($json);
|
||||
|
||||
|
||||
return ($block->dividend / 100);
|
||||
}
|
||||
|
||||
public function getUdAmount ($date) {
|
||||
|
||||
$udFilename = $this->getUdFilename($date);
|
||||
$udsCacheDir = $this->cacheDir . 'uds/';
|
||||
$udFullPath = $udsCacheDir . $udFilename;
|
||||
|
||||
if ($this->isActivatedCache) {
|
||||
|
||||
if (file_exists($udFullPath)) {
|
||||
|
||||
$udCachedAmount = file_get_contents($udFullPath);
|
||||
|
||||
if (is_numeric($udCachedAmount) and $udCachedAmount != 0) {
|
||||
|
||||
$udAmount = floatval($udCachedAmount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!isset($udAmount)) {
|
||||
|
||||
$udAmount = $this->fetchUdAmount($date);
|
||||
|
||||
// Cache UD amount
|
||||
|
||||
if (!file_exists($udsCacheDir)) {
|
||||
|
||||
mkdir($udsCacheDir, 0777, true);
|
||||
|
||||
}
|
||||
|
||||
file_put_contents($udFullPath, $udAmount);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
$udAmount = $this->fetchUdAmount($date);
|
||||
|
||||
}
|
||||
|
||||
return $udAmount;
|
||||
}
|
||||
|
||||
|
||||
protected function getUdFilename ($date) {
|
||||
|
||||
$datePreviousAutumnEquinox = new DateTime($date->format('Y') . '-09-22');
|
||||
$datePreviousSpringEquinox = new DateTime($date->format('Y') . '-03-20');
|
||||
|
||||
if ($date > $datePreviousAutumnEquinox) {
|
||||
|
||||
$udFilename = $date->format('Y') . '-autumn';
|
||||
|
||||
} elseif ($date > $datePreviousSpringEquinox) {
|
||||
|
||||
$udFilename = $date->format('Y') . '-spring';
|
||||
|
||||
} else {
|
||||
|
||||
$udFilename = ($date->sub(new DateInterval('P1Y'))->format('Y')). '-autumn';
|
||||
}
|
||||
|
||||
return $udFilename . '.txt';
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
class Fred {
|
||||
|
||||
private $gatewayProtocol = 'http';
|
||||
|
||||
private $gatewayDomain = 'libra.copylaradio.com';
|
||||
|
||||
private $gatewayPort = '1234';
|
||||
|
||||
private $gatewayDelay = 3;
|
||||
|
||||
public function __construct () {
|
||||
|
||||
}
|
||||
|
||||
public function donneMoiLaPutainDeClefIPNS ($prenomNom, $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday) {
|
||||
|
||||
$salt = $prenomNom;
|
||||
$pepper = $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday;
|
||||
|
||||
$query = 'salt='. $salt .'&pepper='. $pepper;
|
||||
|
||||
$page1 = @file_get_contents($this->gatewayProtocol . '://'. $this->gatewayDomain .':' . $this->gatewayPort . '/?' . $query)
|
||||
or die('<p>On a fait du sale.</p>');
|
||||
|
||||
preg_match("`url='([^']+)'`isU", $page1, $matches);
|
||||
|
||||
$url = $matches[1];
|
||||
|
||||
sleep($this->gatewayDelay);
|
||||
|
||||
$page2 = @file_get_contents($url)
|
||||
or die('</p>On a chié dans la colle.</p>');
|
||||
|
||||
preg_match("`url='.*/ipns/([^']+)'`isU", $page2, $matches);
|
||||
|
||||
$ipnsKey = $matches[1];
|
||||
|
||||
return $ipnsKey;
|
||||
}
|
||||
|
||||
public function donneMoiSesPutainDeMessagesGchange ($prenomNom, $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday, $gchangeId) {
|
||||
|
||||
|
||||
$salt = $prenomNom;
|
||||
$pepper = $nomDuChienSuivieDeLaDateDeNaissanceDeJohnnyHallyday;
|
||||
|
||||
$query = 'salt='. $salt .'&pepper='. $pepper . '&messaging=' . $gchangeId;
|
||||
|
||||
$url = $this->gatewayProtocol . '://'. $this->gatewayDomain .':' . $this->gatewayPort . '/?' . $query;
|
||||
|
||||
echo '<pre>'; var_dump(htmlspecialchars($url)); echo '</pre>';
|
||||
|
||||
$page1 = file_get_contents($url)
|
||||
or die('<p>On a fait du sale.</p>');
|
||||
|
||||
echo '<pre>'; var_dump(htmlspecialchars($page1)); echo '</pre>';
|
||||
|
||||
preg_match("`url='([^']+)'`isU", $page1, $matches);
|
||||
|
||||
$url = $matches[0];
|
||||
|
||||
echo '<pre>'; var_dump($url); echo '</pre>';
|
||||
|
||||
$page2 = '';
|
||||
|
||||
while (empty($page2)) {
|
||||
|
||||
sleep($this->gatewayDelay);
|
||||
|
||||
$page2 = @file_get_contents($url);
|
||||
}
|
||||
|
||||
echo '<pre>'; var_dump($page2); echo '</pre>';
|
||||
|
||||
die();
|
||||
|
||||
$json = $page2;
|
||||
|
||||
return $page1;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,279 @@
|
||||
<?php
|
||||
|
||||
require_once('DAO.class.php');
|
||||
|
||||
class Gchange {
|
||||
|
||||
private $dao;
|
||||
|
||||
private $cacheDir = __DIR__ . '/../cache/';
|
||||
|
||||
private $isActivatedCache = true;
|
||||
|
||||
private $cacheLongevity = array(
|
||||
'placesNearby' => 604800, // 3 jours
|
||||
'users' => 43200, // 12 heures
|
||||
'records' => 900 // 15 min
|
||||
);
|
||||
|
||||
public function __construct () {
|
||||
|
||||
$this->dao = DAO::getInstance();
|
||||
}
|
||||
|
||||
public function getRecordsByIssuer ($issuer) {
|
||||
|
||||
|
||||
$recordsCacheDir = 'records/user/';
|
||||
$recordsCacheFile = $issuer . '.json';
|
||||
|
||||
$json = $this->getJsonFromCache($recordsCacheDir, $recordsCacheFile, $this->cacheLongevity['records']);
|
||||
|
||||
if (empty($json)) {
|
||||
|
||||
$n = 20;
|
||||
|
||||
$queryParams = [
|
||||
'size' => $n,
|
||||
'query' => [
|
||||
'bool' =>[
|
||||
'must' => [
|
||||
'term' => [
|
||||
'issuer' => $issuer
|
||||
]
|
||||
],
|
||||
'must_not' => [
|
||||
[ "term" => ["stock" => 0] ]
|
||||
]
|
||||
]
|
||||
],
|
||||
'sort' => [
|
||||
['time' => 'desc']
|
||||
]
|
||||
];
|
||||
|
||||
$json = $this->dao->fetchJson('/market/record/_search', 'gchange', $queryParams);
|
||||
|
||||
$this->cacheJson($recordsCacheDir, $recordsCacheFile, $json);
|
||||
}
|
||||
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result->hits->hits;
|
||||
|
||||
}
|
||||
|
||||
private function getJsonFromCache ($dir, $file, $cacheLongevity) {
|
||||
|
||||
if (!$this->isActivatedCache) {
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
$json = null;
|
||||
$jsonFullPath = $this->cacheDir . $dir . $file;
|
||||
|
||||
if (file_exists($jsonFullPath) and ((time() - filemtime($jsonFullPath)) < $cacheLongevity)) {
|
||||
|
||||
$json = file_get_contents($jsonFullPath);
|
||||
}
|
||||
|
||||
return $json;
|
||||
|
||||
}
|
||||
|
||||
private function cacheJson ($dir, $file, $json) {
|
||||
|
||||
if (!$this->isActivatedCache) {
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$jsonCacheDir = $this->cacheDir . $dir;
|
||||
$jsonFullPath = $jsonCacheDir . $file;
|
||||
|
||||
if (!file_exists($jsonCacheDir)) {
|
||||
|
||||
mkdir($jsonCacheDir, 0777, true);
|
||||
|
||||
}
|
||||
|
||||
file_put_contents($jsonFullPath, $json);
|
||||
}
|
||||
|
||||
public function getUser ($pubkey) {
|
||||
|
||||
$usersCacheDir = 'users/';
|
||||
$usersCacheFile = $pubkey . '.json';
|
||||
|
||||
$json = $this->getJsonFromCache($usersCacheDir, $usersCacheFile, $this->cacheLongevity['users']);
|
||||
|
||||
if (empty($json)) {
|
||||
|
||||
$json = $this->dao->fetchJson(('/user/profile/'. $pubkey), 'gchange');
|
||||
|
||||
$this->cacheJson($usersCacheDir, $usersCacheFile, $json);
|
||||
}
|
||||
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getPlacesNearUser ($user, $radius) {
|
||||
|
||||
$placesCacheDir = 'places-nearby/user/';
|
||||
$placesCacheFile = $user->_id . '.json';
|
||||
|
||||
$json = $this->getJsonFromCache($placesCacheDir, $placesCacheFile, $this->cacheLongevity['placesNearby']);
|
||||
|
||||
if (empty($json)) {
|
||||
|
||||
$json = $this->getNearbyPlacesJson($user->_source->geoPoint->lat, $user->_source->geoPoint->lon, RADIUS);
|
||||
|
||||
$this->cacheJson($placesCacheDir, $placesCacheFile, $json);
|
||||
|
||||
}
|
||||
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result->hits->hits;
|
||||
}
|
||||
|
||||
public function getNearbyPlaces ($lat, $lon, $maxDistance, $minDistance = NULL) {
|
||||
|
||||
$json = $this->getNearbyPlacesJson($lat, $lon, $maxDistance, $minDistance);
|
||||
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result->hits->hits;
|
||||
}
|
||||
|
||||
|
||||
public function getNearbyPlacesJson ($lat, $lon, $maxDistance, $minDistance = NULL) {
|
||||
|
||||
$n = 20;
|
||||
|
||||
$queryParams = [
|
||||
'size' => $n,
|
||||
'query' => [
|
||||
'bool' => [
|
||||
'must' => [
|
||||
[
|
||||
'geo_distance' => [
|
||||
|
||||
"distance" => $maxDistance . 'km',
|
||||
"geoPoint"=> [
|
||||
"lat" => $lat,
|
||||
"lon" => $lon
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$json = $this->dao->fetchJson('/page/record/_search', 'gchange', $queryParams);
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function getNearbyRecords ($lat, $lon, $maxDistance, $minDistance = NULL) {
|
||||
|
||||
$n = 20;
|
||||
|
||||
$queryParams = [
|
||||
'size' => $n,
|
||||
'query' => [
|
||||
'bool' => [
|
||||
'must' => [
|
||||
[
|
||||
'geo_distance' => [
|
||||
|
||||
"distance" => $maxDistance . 'km',
|
||||
"geoPoint"=> [
|
||||
"lat" => $lat,
|
||||
"lon" => $lon
|
||||
]
|
||||
]
|
||||
], [
|
||||
'range' => [
|
||||
'stock' => [
|
||||
'gte' => 1
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$json = $this->dao->fetchJson('/market/record/_search?pretty', 'gchange', $queryParams);
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result->hits->hits;
|
||||
}
|
||||
|
||||
public function getImmaterialRecords () {
|
||||
|
||||
$n = 20;
|
||||
|
||||
$queryParams = [
|
||||
'size' => $n,
|
||||
'query' => [
|
||||
'nested' => [
|
||||
'path' => 'category',
|
||||
'query' => [
|
||||
'bool' => [
|
||||
'should' => [
|
||||
[ 'term' => [ 'category.parent' => 'cat31' ] ],
|
||||
[ 'term' => [ 'category.id' => 'cat31' ] ],
|
||||
[ 'term' => [ 'category.parent' => 'cat74' ] ],
|
||||
[ 'term' => [ 'category.id' => 'cat74' ] ]
|
||||
],
|
||||
'must_not' => [
|
||||
[ "term" => ["category.id" => "cat65"] ]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$json = $this->dao->fetchJson('/market/record/_search?pretty', 'gchange', $queryParams);
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result->hits->hits;
|
||||
}
|
||||
|
||||
public function getShippable () {
|
||||
|
||||
$n = 20;
|
||||
|
||||
$queryParams = [
|
||||
'size' => $n,
|
||||
'query' => [
|
||||
'match' => [
|
||||
'description' => 'envoi possible'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$json = $this->dao->fetchJson('/market/record/_search?pretty', 'gchange', $queryParams);
|
||||
$result = json_decode($json);
|
||||
|
||||
return $result->hits->hits;
|
||||
}
|
||||
|
||||
public function getHousingOffers () {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getShippableOffers () {
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Location {
|
||||
|
||||
const API_URL = 'http://nominatim.openstreetmap.org/search?q=%s&format=json';
|
||||
|
||||
|
||||
private $lat;
|
||||
|
||||
private $lon;
|
||||
|
||||
private $name;
|
||||
|
||||
private $city;
|
||||
|
||||
private $postCode;
|
||||
|
||||
private $successfulQuery;
|
||||
|
||||
|
||||
public function __construct () {
|
||||
|
||||
}
|
||||
|
||||
public function fetchOpenStreetMap ($searchQuery) {
|
||||
|
||||
$json = NULL;
|
||||
|
||||
$streamContext = stream_context_create(
|
||||
array(
|
||||
"http" => array(
|
||||
"header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$url = sprintf(Location::API_URL, urlencode($searchQuery));
|
||||
$json = @file_get_contents($url, false, $streamContext);
|
||||
|
||||
if (!empty($json)) {
|
||||
|
||||
$json = json_decode($json);
|
||||
}
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
public function createFromAddress ($searchTerms) {
|
||||
|
||||
if (is_array($searchTerms)) {
|
||||
|
||||
while (!empty($searchTerms)) {
|
||||
|
||||
$searchQuery = implode(' ', $searchTerms);
|
||||
$results = Location::fetchOpenStreetMap($searchQuery);
|
||||
|
||||
if (empty($json)) {
|
||||
|
||||
$searchTerms = array_slice($searchTerms, 0, -1);
|
||||
|
||||
} else {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$searchQuery = $searchTerms;
|
||||
$results = Location::fetchOpenStreetMap($searchQuery);
|
||||
}
|
||||
|
||||
if (isset($results[0])) {
|
||||
|
||||
$firstResult = $results[0];
|
||||
|
||||
$loc = new Location();
|
||||
|
||||
$loc->setPosition($firstResult->lat, $firstResult->lon);
|
||||
$loc->successfulQuery = $searchQuery;
|
||||
|
||||
return $loc;
|
||||
|
||||
} else {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function setPosition ($lat, $lon) {
|
||||
|
||||
$this->lat = $lat;
|
||||
$this->lon = $lon;
|
||||
}
|
||||
|
||||
public function getPosition () {
|
||||
|
||||
return [$this->lat, $this->lon];
|
||||
}
|
||||
|
||||
public function getSuccessfulQuery () {
|
||||
|
||||
return $this->successfulQuery;
|
||||
}
|
||||
|
||||
|
||||
public function getLat () {
|
||||
|
||||
return $this->lat;
|
||||
}
|
||||
|
||||
|
||||
public function getLon () {
|
||||
|
||||
return $this->lon;
|
||||
}
|
||||
|
||||
static public function geoDist (Location $p1, Location $p2) {
|
||||
|
||||
// https://stackoverflow.com/questions/365826/calculate-distance-between-2-gps-coordinates
|
||||
|
||||
$pos1 = $p1->getPosition();
|
||||
$pos2 = $p2->getPosition();
|
||||
|
||||
$a = sin(deg2rad($pos2[0]-$pos1[0])/2)**2 + sin(deg2rad($pos2[1]-$pos1[1])/2)**2 * cos(deg2rad($pos1[0])) * cos(deg2rad($pos2[0]));
|
||||
|
||||
return 12742 * atan2(sqrt($a), sqrt(1-$a));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,281 @@
|
||||
<?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;
|
||||
|
||||