proto
This commit is contained in:
commit
be7c68a8db
|
@ -0,0 +1 @@
|
||||||
|
data.gchange.fr
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
define('RADIUS', '100km');
|
||||||
|
define('BB_URL', 'https://framalistes.org/sympa/info/vannes.monnaielibre');
|
||||||
|
|
||||||
|
|
||||||
|
require_once('functions.php');
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?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,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>gMaville</title>
|
||||||
|
<style>
|
||||||
|
td.date {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>gMaville - Toutes les infos pertinentes pour vous</h1>
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
include('header.php');
|
||||||
|
|
||||||
|
if (!isset($_POST['city'])) {
|
||||||
|
|
||||||
|
echo '
|
||||||
|
<h2>Où êtes-vous ?</h2>
|
||||||
|
|
||||||
|
<form method="post" action="mytown.php">
|
||||||
|
<p>
|
||||||
|
<label>Ville :
|
||||||
|
<input type="text" name="city" />
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="submit" value="Voir tout ce qui se passe de cool autour de chez moi" />
|
||||||
|
</p>
|
||||||
|
</form>';
|
||||||
|
}
|
||||||
|
|
||||||
|
include('footer.php');
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
"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,586 @@
|
||||||
|
<?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 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é.');
|
||||||
|
$out[] = _('Noeud interrogés : ');
|
||||||
|
|
||||||
|
if (isset($queryParams)) {
|
||||||
|
|
||||||
|
$out[] = _('Paramètres de la requête : ');
|
||||||
|
$out[] = print_r($queryParams, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$out = array_merge($out, $nodes);
|
||||||
|
|
||||||
|
$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,110 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('DAO.class.php');
|
||||||
|
|
||||||
|
class Gchange {
|
||||||
|
|
||||||
|
private $dao;
|
||||||
|
|
||||||
|
public function __construct () {
|
||||||
|
|
||||||
|
$this->dao = DAO::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNearbyOffers ($lat, $lon, $max, $min = NULL) {
|
||||||
|
|
||||||
|
$n = 20;
|
||||||
|
|
||||||
|
$queryParams = [
|
||||||
|
'size' => $n,
|
||||||
|
'query' => [
|
||||||
|
'bool' => [
|
||||||
|
'must' => [
|
||||||
|
[
|
||||||
|
'geo_distance' => [
|
||||||
|
|
||||||
|
"distance" => "50km",
|
||||||
|
"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 getImmaterialOffers () {
|
||||||
|
|
||||||
|
$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,157 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
require_once('config.php');
|
||||||
|
|
||||||
|
|
||||||
|
require_once('lib/Gchange.class.php');
|
||||||
|
require_once('lib/CesiumPlus.class.php');
|
||||||
|
|
||||||
|
$gchange = new Gchange();
|
||||||
|
$cesiumPlus = new CesiumPlus();
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($_POST['city'])) {
|
||||||
|
|
||||||
|
$_SESSION['city'] = $_POST['city'];
|
||||||
|
|
||||||
|
$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 = 'http://nominatim.openstreetmap.org/search?q='. urlencode($_POST['city']) . '&format=json';
|
||||||
|
|
||||||
|
$citiesJson = file_get_contents($url, false, $streamContext);
|
||||||
|
$cities = json_decode($citiesJson);
|
||||||
|
|
||||||
|
$_SESSION['lat'] = $cities[0]->lat;
|
||||||
|
$_SESSION['lon'] = $cities[0]->lon;
|
||||||
|
$_SESSION['city'] = htmlspecialchars($_POST['city']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include('header.php');
|
||||||
|
|
||||||
|
|
||||||
|
echo '<h2>Événements à venir près de '. $_SESSION['city'] . '</h2>';
|
||||||
|
|
||||||
|
echo '<p>Pas d\'événement prévu en ce moment.</p>';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo '<h2>Contacter d\'autres junistes près de '. $_SESSION['city'] . '</h2>';
|
||||||
|
|
||||||
|
echo '
|
||||||
|
<p>
|
||||||
|
<a href="'. BB_URL . '">
|
||||||
|
Groupe de discussion par mail du groupe de '. $_SESSION['city']. '
|
||||||
|
</a>
|
||||||
|
</p>';
|
||||||
|
|
||||||
|
|
||||||
|
$users = $cesiumPlus->getNearbyUsers($_SESSION['lat'], $_SESSION['lon'], RADIUS);
|
||||||
|
|
||||||
|
echo '<h2>Nouveaux utilisateurs à '. RADIUS . ' autour de '. $_SESSION['city'] .'</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>';
|
||||||
|
|
||||||
|
|
||||||
|
$offers = $gchange->getNearbyOffers($_SESSION['lat'], $_SESSION['lon'], RADIUS);
|
||||||
|
|
||||||
|
echo '<h2>Annonces à '. RADIUS . ' autour de '. $_SESSION['city'] .'</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>';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$offers = $gchange->getShippable();
|
||||||
|
|
||||||
|
echo '<h2>Envoi possible</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>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
';
|
||||||
|
}
|
||||||
|
echo '</ol>';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$offers = $gchange->getImmaterialOffers();
|
||||||
|
|
||||||
|
echo '<h2>Annonces d\'ordre "immatériel"</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>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
';
|
||||||
|
}
|
||||||
|
echo '</ol>';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
include('footer.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue