Liste des évènements via un squelette en remplacement du script php
This commit is contained in:
parent
9d435b2616
commit
d37fa4149f
@ -3,7 +3,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Liste des évènements</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=#CHARSET" />
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
@ -27,14 +27,7 @@ border-color: #999;
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<BOUCLE_evenements(DATA) {source json, "https://www.agendadulibre.org/events.json?region=&tag=libre-en-fete-2018"}{par id}{inverse}>
|
||||
<tr>
|
||||
<td><a href="http://www.agendadulibre.org/events/[(#VALEUR{id})]">#VALEUR{id}</a></td>
|
||||
<td>[(#VALEUR{start_time}|affdate_jourcourt)]</td>
|
||||
<td>#VALEUR{title}</td>
|
||||
<td>#VALEUR{city}</td>
|
||||
</tr>
|
||||
</BOUCLE_evenements>
|
||||
[(#ENV{annee}|lef_liste_evenements)]
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -207,3 +207,81 @@ function mes_compare($a, $b) {
|
||||
$coll = collator_create( 'fr_FR' );
|
||||
return collator_compare($coll, $a, $b);
|
||||
}
|
||||
|
||||
/************************************
|
||||
* Spécial filtre liste des évènements
|
||||
* Le chemin du répertoire IMG est codé en dur !
|
||||
*************************************/
|
||||
|
||||
function filtre_lef_liste_evenements($annee) {
|
||||
$IMG_ROOT = "/var/lib/spip/sites/www.libre-en-fete.net/";
|
||||
if (!is_numeric($annee)) {
|
||||
return "Paramètre année incorrect";
|
||||
}
|
||||
|
||||
$tag = "libre-en-fete-".$annee;
|
||||
$jsonString = file_get_contents("https://www.agendadulibre.org/events.json?future=false&tag=".$tag);
|
||||
$json = json_decode($jsonString, TRUE);
|
||||
$evenementCount = count($json);
|
||||
if ($evenementCount == 0) {
|
||||
return "Aucun évènement";
|
||||
}
|
||||
$currentTime = date(DATE_ATOM);
|
||||
$dirPath = $IMG_ROOT."IMG/agendadulibre/".$annee;
|
||||
if (!file_exists($dirPath)) {
|
||||
mkdir($dirPath, 0777, TRUE);
|
||||
}
|
||||
$evenementArray = array();
|
||||
for($i = 0; $i < $evenementCount; $i++) {
|
||||
$evenement = $json[$i];
|
||||
$id = $evenement["id"];
|
||||
$path = $dirPath."/".$id;
|
||||
if (file_exists($path)) {
|
||||
$time = file_get_contents($path);
|
||||
} else {
|
||||
$time = $currentTime;
|
||||
$fp = fopen($path, 'w');
|
||||
fwrite($fp, $time);
|
||||
fclose($fp);
|
||||
}
|
||||
$evenement["time"] = $time;
|
||||
$evenementArray[] = $evenement;
|
||||
}
|
||||
usort($evenementArray, "lef_comparaison");
|
||||
$result = "";
|
||||
for($i = 0; $i < $evenementCount; $i++) {
|
||||
$evenement = $evenementArray[$i];
|
||||
$increment = ($evenementCount - $i);
|
||||
$date = date_create($evenement["start_time"]);
|
||||
$result .= "<tr>";
|
||||
$result .= "<td>".$increment."</td>";
|
||||
$result .= '<td><a href="http://www.agendadulibre.org/events/'.$evenement["id"].'">'.$evenement["id"]."</a></td>";
|
||||
$result .= "<td>".date_format($date, 'd/m')."</td>";
|
||||
$result .= "<td>".$evenement["title"]."</td>";
|
||||
$result .= "<td>".$evenement["city"]."</td>";
|
||||
$result .= "<td>".$evenement["time"]."</td>";
|
||||
$result .= "<td>".$evenement["contact"]."</td>";
|
||||
$result .= "</tr>";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function lef_comparaison($evt1, $evt2) {
|
||||
$time1 = $evt1["time"];
|
||||
$time2 = $evt2["time"];
|
||||
if ($time1 > $time2) {
|
||||
return -1;
|
||||
}
|
||||
if ($time1 < $time2) {
|
||||
return 1;
|
||||
}
|
||||
$id1 = $evt1["id"];
|
||||
$id2 = $evt2["id"];
|
||||
if ($id1 > $id2) {
|
||||
return -1;
|
||||
}
|
||||
if ($id1 < $id2) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user