modif du webring pour passer en statique partout sauf le hub
This commit is contained in:
parent
c5200cac35
commit
1a10796e1a
2 changed files with 60 additions and 4 deletions
18
README.md
18
README.md
|
|
@ -9,9 +9,19 @@
|
|||
"img_link": "lien_vers_une_image_pour_une_illustration"
|
||||
}
|
||||
```
|
||||
- rajouter ces deux lignes au bas de son footer (ou quelque-part d'autre)
|
||||
- rajouter ces lignes au bas de son footer (ou quelque-part d'autre)
|
||||
```html
|
||||
<webring-iutechno site="url_de_votre_site_dans_le_json"></webring-iutechno>
|
||||
<script src="./webring.js"></script>
|
||||
<div class="grossomodo-webring">
|
||||
<div class="webring-inner">
|
||||
<h3 class="webring-title">
|
||||
<span class="spacer"></span>
|
||||
<span>grossomodo</span>
|
||||
</h3>
|
||||
<a href="https://hub.gablaxy.xyz/ring?direction=prev" rel="prev noreferrer external">< prev</a>
|
||||
/
|
||||
<a href="https://hub.gablaxy.xyz/">hub</a>
|
||||
/
|
||||
<a href="https://hub.gablaxy.xyz/ring?direction=next" rel="next noreferrer external">suiv ></a>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
- télécharger le fichier webring.js sur votre site et éditez le chemin du script ci dessus en conséquence, pour l'instant ça marche comme ça mais quand j'aurais un serveur perso vous pourrez passer un lien vers ce serveur pour avoir la dernière version du script.
|
||||
|
|
|
|||
46
ring.php
Normal file
46
ring.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
// script de redirection pour le webring
|
||||
$direction = $_GET['direction'] ?? '';
|
||||
if (!in_array($direction, ['prev', 'next'])) {
|
||||
http_response_code(400);
|
||||
die('Direction invalide.');
|
||||
}
|
||||
|
||||
// Récupère l'URL du site d'où vient l'utilisateur
|
||||
$referer = $_SERVER['HTTP_REFERER'] ?? '';
|
||||
if (!$referer) {
|
||||
http_response_code(400);
|
||||
die('Referer manquant.');
|
||||
}
|
||||
|
||||
// Nettoie l'URL du qui arrive
|
||||
$referer = rtrim(explode('?', $referer)[0], '/');
|
||||
$sites_json = file_get_contents('webring.json');
|
||||
$sites = json_decode($sites_json, true);
|
||||
|
||||
if (!$sites) {
|
||||
http_response_code(500);
|
||||
die('Configuration du webring introuvable.');
|
||||
}
|
||||
|
||||
// cherche dans la liste
|
||||
$index = array_search($referer, array_column($sites, 'url'));
|
||||
|
||||
if ($index === false) {
|
||||
http_response_code(404);
|
||||
die('Site non membre du webring.');
|
||||
}
|
||||
|
||||
// calcul du voisin
|
||||
$count = count($sites);
|
||||
if ($direction === 'next') {
|
||||
$targetIndex = ($index + 1) % $count;
|
||||
} else {
|
||||
$targetIndex = ($index - 1 + $count) % $count;
|
||||
}
|
||||
|
||||
$targetUrl = $sites[$targetIndex]['url'];
|
||||
|
||||
// redirection
|
||||
header("Location: $targetUrl", true, 302);
|
||||
exit;
|
||||
Loading…
Reference in a new issue