From efd79d15adef2a27347c25ebb19754e9937f9715 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 10 Sep 2025 01:02:36 +0200 Subject: =?UTF-8?q?modification=20d'une=20URL=20page=20Menu=20et=20chemin,?= =?UTF-8?q?=20htmlspecialchars=20sur=20les=20URL=20du=20menu=20=C3=A0=20l'?= =?UTF-8?q?affichage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/MenuAndPathsController.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/controller') diff --git a/src/controller/MenuAndPathsController.php b/src/controller/MenuAndPathsController.php index d429287..5779b39 100644 --- a/src/controller/MenuAndPathsController.php +++ b/src/controller/MenuAndPathsController.php @@ -14,9 +14,15 @@ class MenuAndPathsController $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); $parent = $previous_page->getParent(); + $url_input = trim($_POST["url_input"]); // faire htmlspecialchars à l'affichage + if(!filter_var($url_input, FILTER_VALIDATE_URL) || !str_starts_with($url_input, 'http')){ + header("Location: " . new URL(['page' => $_GET['from'], 'error' => 'invalide_url'])); + die; + } + $page = new Page( trim(htmlspecialchars($_POST["label_input"])), - filter_var($_POST["url_input"], FILTER_VALIDATE_URL), + $url_input, true, true, false, $previous_page->getPosition(), $parent); // peut et DOIT être null si on est au 1er niveau @@ -24,7 +30,7 @@ class MenuAndPathsController // on a donné à la nouvelle entrée la même position qu'à la précédente, // addChild l'ajoute à la fin du tableau "children" puis on trie // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position - if($parent == null){ + if(!$parent){ $parent = Director::$menu_data; } $parent->addChild($page); // true pour réindexer les positions en BDD @@ -36,6 +42,25 @@ class MenuAndPathsController die; } + static public function editUrlEntry(EntityManager $entityManager, array $json): void + { + $url_input = trim($json['url_input']); // faire htmlspecialchars à l'affichage + $page = $entityManager->find('App\Entity\Page', $json['id']); + + if(!$page){ + echo json_encode(['success' => false, 'message' => "id invalide"]); + } + elseif(!filter_var($url_input, FILTER_VALIDATE_URL) || !str_starts_with($url_input, 'http')){ + echo json_encode(['success' => false, 'message' => "la chaîne envoyée n'est pas une URL valide"]); + } + else{ + $page->setEndOfPath($url_input); + $entityManager->flush(); + echo json_encode(['success' => true, 'url_input' => $url_input]); + } + die; + } + static public function deleteUrlMenuEntry(EntityManager $entityManager): void { Director::$menu_data = new Menu($entityManager); @@ -163,7 +188,6 @@ class MenuAndPathsController else{ echo json_encode(['success' => false]); } - die; } -- cgit v1.2.3