From 28698982ff6dc67a331788c2637bce8689121769 Mon Sep 17 00:00:00 2001 From: polo-pc-greta Date: Thu, 8 May 2025 12:32:34 +0200 Subject: =?UTF-8?q?modif=20page,=20cr=C3=A9ation=20d'un=20bloc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/Director.php | 26 ++++++++++++++++++++++--- src/controller/Security.php | 4 +++- src/controller/post.php | 47 ++++++++++++++++++++++++++++++++++++++------- 3 files changed, 66 insertions(+), 11 deletions(-) (limited to 'src/controller') diff --git a/src/controller/Director.php b/src/controller/Director.php index a2528ed..56a90cb 100644 --- a/src/controller/Director.php +++ b/src/controller/Director.php @@ -16,11 +16,11 @@ class Director private Node $node; private Node $article; - public function __construct(EntityManager $entityManager, bool $for_display = false) + public function __construct(EntityManager $entityManager, bool $get_menu = false) { $this->entityManager = $entityManager; - if($for_display){ - self::$menu_data = new Menu($entityManager); // Menu est un modèle mais pas une entité + if($get_menu){ + self::$menu_data = new Menu($entityManager); self::$page_path = new Path(); $this->page = self::$page_path->getLast(); } @@ -137,4 +137,24 @@ class Director $this->node = $section; return true; } + + public function findNodeByName(string $name): void + { + $bulk_data = $this->entityManager + ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.name_node = :name') + ->setParameter('name', $name) + ->getResult(); + $this->node = $bulk_data[0]; + echo $this->page->getPageName() . ' '; + + $bulk_data = $this->entityManager + ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent AND n.page = :page') + ->setParameter('parent', $this->node) + ->setParameter('page', $this->page) + ->getResult(); + foreach($bulk_data as $child){ + $this->node->addChild($child); + echo $child->getName() . ' '; + } + } } diff --git a/src/controller/Security.php b/src/controller/Security.php index f9092e2..7d592e9 100644 --- a/src/controller/Security.php +++ b/src/controller/Security.php @@ -3,6 +3,8 @@ // // htmlawed nettoie les entrées de l'utilisateur, en particulier le html de l'éditeur +declare(strict_types=1); + class Security { private static $configHtmLawed = array( @@ -14,10 +16,10 @@ class Security // liste noire d'attributs HTML 'deny_attribute'=> 'id, class' // on garde 'style' ); - // faire qu'un certain élément puisse n'avoir que certains attributs, regarder la doc private static $specHtmLawed = ''; + // ATTENTION, n'applique pas htmlspecialchars() !! public static function secureString(string $chaine): string { return trim(htmLawed($chaine, self::$configHtmLawed, self::$specHtmLawed));; diff --git a/src/controller/post.php b/src/controller/post.php index d2e4477..76ac72b 100644 --- a/src/controller/post.php +++ b/src/controller/post.php @@ -3,6 +3,8 @@ declare(strict_types=1); +use App\Entity\Node; +use App\Entity\NodeData; use App\Entity\Page; if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) @@ -10,17 +12,48 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) /* -- formulaires HTML classiques -- */ if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') { - // création d'une entrée de menu avec une URL - if(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ - echo $_POST["label_input"] . '
'; - echo $_POST["url_input"] . '
'; - echo $_POST["location"] . '
'; // id entrée précédente + /* -- mode Modification d'une page -- */ + + // ajout d'un bloc dans une page + if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ + $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data + $page = Director::$page_path->getLast(); + $director->findNodeByName('main'); + $main = $director->getNode(); + $position = count($main->getChildren()) + 1; // position dans la fraterie + + $bloc = new Node( + trim(htmlspecialchars($_POST["bloc_select"])), + null, [], + $position, + $main, + $page); + $data = new NodeData( + ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], + $bloc); + + $entityManager->persist($bloc); + $entityManager->persist($data); + $entityManager->flush(); + header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); + } + + /* -- page Menu et chemins -- */ + + // création d'une entrée de menu avec une URL + elseif(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ Director::$menu_data = new Menu($entityManager); $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); $parent = $previous_page->getParent(); - $page = new Page($_POST["label_input"], $_POST["url_input"], true, true, false, $previous_page->getPosition(), $parent); + $page = new Page( + trim(htmlspecialchars($_POST["label_input"])), + filter_var($_POST["url_input"], FILTER_VALIDATE_URL), + true, true, false, + $previous_page->getPosition(), + $parent); + // on indique pour la nouvelle entrée la même position que la précédente, puis addChild l'ajoute à la fin du tableau "children" avant de déclencher un tri // 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){ @@ -31,7 +64,6 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) $entityManager->persist($page); $entityManager->flush(); - header("Location: " . new URL(['page' => $_GET['from']])); } // suppression d'une entrée de menu avec une URL @@ -54,6 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) header("Location: " . new URL(['error' => 'paramètres inconnus'])); } } + /* -- requêtes AJAX -- */ else{ require '../src/controller/ajax.php'; -- cgit v1.2.3