diff options
author | polo-pc-greta <ordipolo@gmx.fr> | 2025-05-08 12:32:34 +0200 |
---|---|---|
committer | polo-pc-greta <ordipolo@gmx.fr> | 2025-05-08 12:32:34 +0200 |
commit | 28698982ff6dc67a331788c2637bce8689121769 (patch) | |
tree | 6df30593fdcdd2ead77dd894467e5031a31cfde9 /src/controller | |
parent | 2d8ec75f4aaf3b93fd9f6758f8dcb4f1f9f03d0c (diff) | |
download | cms-28698982ff6dc67a331788c2637bce8689121769.zip |
modif page, création d'un bloc
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/Director.php | 26 | ||||
-rw-r--r-- | src/controller/Security.php | 4 | ||||
-rw-r--r-- | src/controller/post.php | 47 |
3 files changed, 66 insertions, 11 deletions
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 | |||
16 | private Node $node; | 16 | private Node $node; |
17 | private Node $article; | 17 | private Node $article; |
18 | 18 | ||
19 | public function __construct(EntityManager $entityManager, bool $for_display = false) | 19 | public function __construct(EntityManager $entityManager, bool $get_menu = false) |
20 | { | 20 | { |
21 | $this->entityManager = $entityManager; | 21 | $this->entityManager = $entityManager; |
22 | if($for_display){ | 22 | if($get_menu){ |
23 | self::$menu_data = new Menu($entityManager); // Menu est un modèle mais pas une entité | 23 | self::$menu_data = new Menu($entityManager); |
24 | self::$page_path = new Path(); | 24 | self::$page_path = new Path(); |
25 | $this->page = self::$page_path->getLast(); | 25 | $this->page = self::$page_path->getLast(); |
26 | } | 26 | } |
@@ -137,4 +137,24 @@ class Director | |||
137 | $this->node = $section; | 137 | $this->node = $section; |
138 | return true; | 138 | return true; |
139 | } | 139 | } |
140 | |||
141 | public function findNodeByName(string $name): void | ||
142 | { | ||
143 | $bulk_data = $this->entityManager | ||
144 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.name_node = :name') | ||
145 | ->setParameter('name', $name) | ||
146 | ->getResult(); | ||
147 | $this->node = $bulk_data[0]; | ||
148 | echo $this->page->getPageName() . ' '; | ||
149 | |||
150 | $bulk_data = $this->entityManager | ||
151 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent AND n.page = :page') | ||
152 | ->setParameter('parent', $this->node) | ||
153 | ->setParameter('page', $this->page) | ||
154 | ->getResult(); | ||
155 | foreach($bulk_data as $child){ | ||
156 | $this->node->addChild($child); | ||
157 | echo $child->getName() . ' '; | ||
158 | } | ||
159 | } | ||
140 | } | 160 | } |
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 @@ | |||
3 | // | 3 | // |
4 | // htmlawed nettoie les entrées de l'utilisateur, en particulier le html de l'éditeur | 4 | // htmlawed nettoie les entrées de l'utilisateur, en particulier le html de l'éditeur |
5 | 5 | ||
6 | declare(strict_types=1); | ||
7 | |||
6 | class Security | 8 | class Security |
7 | { | 9 | { |
8 | private static $configHtmLawed = array( | 10 | private static $configHtmLawed = array( |
@@ -14,10 +16,10 @@ class Security | |||
14 | // liste noire d'attributs HTML | 16 | // liste noire d'attributs HTML |
15 | 'deny_attribute'=> 'id, class' // on garde 'style' | 17 | 'deny_attribute'=> 'id, class' // on garde 'style' |
16 | ); | 18 | ); |
17 | |||
18 | // faire qu'un certain élément puisse n'avoir que certains attributs, regarder la doc | 19 | // faire qu'un certain élément puisse n'avoir que certains attributs, regarder la doc |
19 | private static $specHtmLawed = ''; | 20 | private static $specHtmLawed = ''; |
20 | 21 | ||
22 | // ATTENTION, n'applique pas htmlspecialchars() !! | ||
21 | public static function secureString(string $chaine): string | 23 | public static function secureString(string $chaine): string |
22 | { | 24 | { |
23 | return trim(htmLawed($chaine, self::$configHtmLawed, self::$specHtmLawed));; | 25 | 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 @@ | |||
3 | 3 | ||
4 | declare(strict_types=1); | 4 | declare(strict_types=1); |
5 | 5 | ||
6 | use App\Entity\Node; | ||
7 | use App\Entity\NodeData; | ||
6 | use App\Entity\Page; | 8 | use App\Entity\Page; |
7 | 9 | ||
8 | if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | 10 | if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) |
@@ -10,17 +12,48 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
10 | /* -- formulaires HTML classiques -- */ | 12 | /* -- formulaires HTML classiques -- */ |
11 | if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') | 13 | if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') |
12 | { | 14 | { |
13 | // création d'une entrée de menu avec une URL | 15 | /* -- mode Modification d'une page -- */ |
14 | if(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ | 16 | |
15 | echo $_POST["label_input"] . '<br>'; | 17 | // ajout d'un bloc dans une page |
16 | echo $_POST["url_input"] . '<br>'; | 18 | if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ |
17 | echo $_POST["location"] . '<br>'; // id entrée précédente | 19 | $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data |
20 | $page = Director::$page_path->getLast(); | ||
21 | $director->findNodeByName('main'); | ||
22 | $main = $director->getNode(); | ||
23 | $position = count($main->getChildren()) + 1; // position dans la fraterie | ||
24 | |||
25 | $bloc = new Node( | ||
26 | trim(htmlspecialchars($_POST["bloc_select"])), | ||
27 | null, [], | ||
28 | $position, | ||
29 | $main, | ||
30 | $page); | ||
31 | $data = new NodeData( | ||
32 | ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], | ||
33 | $bloc); | ||
34 | |||
35 | $entityManager->persist($bloc); | ||
36 | $entityManager->persist($data); | ||
37 | $entityManager->flush(); | ||
38 | header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); | ||
39 | } | ||
18 | 40 | ||
41 | |||
42 | /* -- page Menu et chemins -- */ | ||
43 | |||
44 | // création d'une entrée de menu avec une URL | ||
45 | elseif(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ | ||
19 | Director::$menu_data = new Menu($entityManager); | 46 | Director::$menu_data = new Menu($entityManager); |
20 | $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); | 47 | $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); |
21 | $parent = $previous_page->getParent(); | 48 | $parent = $previous_page->getParent(); |
22 | 49 | ||
23 | $page = new Page($_POST["label_input"], $_POST["url_input"], true, true, false, $previous_page->getPosition(), $parent); | 50 | $page = new Page( |
51 | trim(htmlspecialchars($_POST["label_input"])), | ||
52 | filter_var($_POST["url_input"], FILTER_VALIDATE_URL), | ||
53 | true, true, false, | ||
54 | $previous_page->getPosition(), | ||
55 | $parent); | ||
56 | |||
24 | // 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 | 57 | // 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 |
25 | // 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 | 58 | // 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 |
26 | if($parent == null){ | 59 | if($parent == null){ |
@@ -31,7 +64,6 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
31 | 64 | ||
32 | $entityManager->persist($page); | 65 | $entityManager->persist($page); |
33 | $entityManager->flush(); | 66 | $entityManager->flush(); |
34 | |||
35 | header("Location: " . new URL(['page' => $_GET['from']])); | 67 | header("Location: " . new URL(['page' => $_GET['from']])); |
36 | } | 68 | } |
37 | // suppression d'une entrée de menu avec une URL | 69 | // suppression d'une entrée de menu avec une URL |
@@ -54,6 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
54 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); | 86 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); |
55 | } | 87 | } |
56 | } | 88 | } |
89 | |||
57 | /* -- requêtes AJAX -- */ | 90 | /* -- requêtes AJAX -- */ |
58 | else{ | 91 | else{ |
59 | require '../src/controller/ajax.php'; | 92 | require '../src/controller/ajax.php'; |