From 64b7c08f5846be087d29217a925f1cfe3af2117c Mon Sep 17 00:00:00 2001 From: adrien Date: Sat, 10 May 2025 14:10:37 +0200 Subject: [PATCH] =?UTF-8?q?aper=C3=A7u?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Grille.php | 14 ++++++++---- Trie.php | 2 +- index.php | 13 ++++++----- style.css | 1 + thumbnail.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 thumbnail.php diff --git a/Grille.php b/Grille.php index 8177883..846fe71 100644 --- a/Grille.php +++ b/Grille.php @@ -174,22 +174,26 @@ class Grille implements ArrayAccess public function save($id) { - session_id($id); + if (session_status() === PHP_SESSION_ACTIVE) { + session_write_close(); + } + + session_id("$this->largeur,$this->hauteur,$id"); session_start(["use_cookies" => false]); - $_SESSION["$this->largeur,$this->hauteur"] = (string)$this; + $_SESSION["grille"] = (string)$this; } public function load($id) { - session_id($id); + session_id("$this->largeur,$this->hauteur,$id"); session_start(["use_cookies" => false]); - if (!isset($_SESSION["$this->largeur,$this->hauteur"])) { + if (!isset($_SESSION["grille"])) { return false; } - foreach (explode(PHP_EOL, $_SESSION["$this->largeur,$this->hauteur"]) as $y => $ligne) { + foreach (explode(PHP_EOL, $_SESSION["grille"]) as $y => $ligne) { foreach (str_split($ligne) as $x => $lettre) { $this->grille[$y][$x] = $lettre; } diff --git a/Trie.php b/Trie.php index 42ee6f8..aa424d0 100644 --- a/Trie.php +++ b/Trie.php @@ -6,8 +6,8 @@ class Trie implements ArrayAccess, IteratorAggregate, Countable { private $nb_branches = 0; public function arraySet($cles, $valeur) { - $this->nb_branches++; $cle = $cles[0]; + $this->nb_branches++; $cles = array_slice($cles, 1); if ($cles == []) { $this->branches[$cle] = $valeur; diff --git a/index.php b/index.php index 7556a4d..043a69d 100644 --- a/index.php +++ b/index.php @@ -29,7 +29,10 @@ $largeur = filter_input(INPUT_GET, 'colonnes', FILTER_VALIDATE_INT, [ $grille_valide = false; $grille = new Grille($hauteur, $largeur); $basedir = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].dirname($_SERVER["DOCUMENT_URI"]); -if (!isset($_GET["grille"]) || $_GET["grille"] == "") { + +if (isset($_GET["grille"]) || $_GET["grille"] == "") { + $id = htmlspecialchars($_GET["grille"]); +} else { do { $id = uniqid(); } while (!$grille->genere($id)); @@ -56,16 +59,14 @@ if (!isset($_GET["grille"]) || $_GET["grille"] == "") { - - - + + + "/> load($id) || $grille->genere($id); mt_srand(crc32($id)); diff --git a/style.css b/style.css index e2c299a..a474a66 100644 --- a/style.css +++ b/style.css @@ -108,6 +108,7 @@ h2 { } .grille input[disabled] { + color: black; background-color: black; } diff --git a/thumbnail.php b/thumbnail.php new file mode 100644 index 0000000..8a4d928 --- /dev/null +++ b/thumbnail.php @@ -0,0 +1,63 @@ +load($id) || $grille->genere($id); + + for ($y = 0; $y < $lignes; $y++) { + for ($x = 0; $x < $colonnes; $x++) { + if ($grille[$y][$x] == CASE_NOIRE) { + imagefilledrectangle($image, $gauche + $x * $cote, $haut + $y * $cote, $gauche + ($x + 1) * $cote, $haut + ($y + 1) * $cote, $noir); + } + } + } +} + +// Envoyer l'image au navigateur +header('Content-Type: image/png'); +imagepng($image); + +// Libérer la mémoire +imagedestroy($image); +?> \ No newline at end of file