-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepingler.php
More file actions
41 lines (34 loc) · 1.04 KB
/
epingler.php
File metadata and controls
41 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
header('Content-Type: application/json');
$path = ini_get('upload_tmp_dir');
if (empty($path)) $path = ".";
$path .= "/";
$pins_file = $path . "shasha_pins.json";
$pins = [];
if (file_exists($pins_file)) {
$pins = json_decode(file_get_contents($pins_file), true) ?? [];
}
if (isset($_GET["f"]) && !empty($_GET["f"])) {
$fn = $_GET["f"];
// Validation : seuls les fichiers du format post-[md5].[ext] sont acceptés
if (!preg_match('/^post-[a-f0-9]{32}\.[a-z0-9]{1,5}$/', $fn)) {
echo json_encode(["error" => "Nom de fichier invalide"]);
exit;
}
// Vérification que le fichier existe
if (!file_exists($path . $fn)) {
echo json_encode(["error" => "Fichier introuvable"]);
exit;
}
if (in_array($fn, $pins)) {
$pins = array_values(array_filter($pins, function ($p) use ($fn) { return $p !== $fn; }));
$pinned = false;
} else {
$pins[] = $fn;
$pinned = true;
}
file_put_contents($pins_file, json_encode($pins));
echo json_encode(["pinned" => $pinned]);
} else {
echo json_encode(["error" => "Aucun fichier spécifié"]);
}