aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-09-09 15:37:50 +0200
committerpolo <ordipolo@gmx.fr>2025-09-09 15:37:50 +0200
commit5e41bea598ff38b3c520b69fd92ee3412e716df2 (patch)
treeb4b57a7201db1efe484446383042f9a43fd2deff
parentc5d9df5c42b5d2522e2a06b5f40422c1bbf497ab (diff)
downloadcms-5e41bea598ff38b3c520b69fd92ee3412e716df2.zip
fin de l'utilisation du champ article_timestamp de la table node, résolue erreur lorsque deux news sont créées dans la même minute (pas dans la même seconde par contre)
-rw-r--r--public/css/body.css2
-rw-r--r--public/js/main.js7
-rw-r--r--public/js/menu.js3
-rw-r--r--public/js/tinymce.js8
-rw-r--r--src/URL.php16
-rw-r--r--src/controller/ArticleController.php30
-rw-r--r--src/controller/Director.php6
-rw-r--r--src/controller/PageManagementController.php11
-rw-r--r--src/installation.php30
-rw-r--r--src/model/entities/Node.php10
-rw-r--r--src/router.php5
-rw-r--r--src/view/MainBuilder.php4
-rw-r--r--src/view/NewBuilder.php62
-rw-r--r--src/view/PostBuilder.php2
-rw-r--r--src/view/templates/new.php4
15 files changed, 103 insertions, 97 deletions
diff --git a/public/css/body.css b/public/css/body.css
index af178a8..d60f28c 100644
--- a/public/css/body.css
+++ b/public/css/body.css
@@ -69,7 +69,7 @@ section > h3
69.grid > .section_child 69.grid > .section_child
70{ 70{
71 display: grid; /* et c'est tout */ 71 display: grid; /* et c'est tout */
72 /*grid-template-columns: repeat(auto-fit, minmax(' . $min_width . 'px, 1fr)); */ /* dans PostBlockBuilder et NewsBlockBuilder */ 72 /* la règle grid-template-columns est ajoutée dynamiquement par PHP ou JS*/
73} 73}
74.galery_photos 74.galery_photos
75{ 75{
diff --git a/public/js/main.js b/public/js/main.js
index 8f2b214..2936ea0 100644
--- a/public/js/main.js
+++ b/public/js/main.js
@@ -80,8 +80,9 @@ document.addEventListener('DOMContentLoaded', () => { // pour pouvoir attraper l
80// complète les fonctions dans tinymce.js 80// complète les fonctions dans tinymce.js
81function switchPositions(article_id, direction) 81function switchPositions(article_id, direction)
82{ 82{
83 const current_article = findParentByTagName(document.getElementById(article_id), 'article'); // l'id n'est pas sur la bonne balise 83 const current_article = findParentByTagName(document.getElementById(article_id), 'article'); // l'id n'est pas toujours sur la même balise
84 var other_article; 84 let other_article;
85 let other_article_id;
85 86
86 if(direction == 'down'){ 87 if(direction == 'down'){
87 other_article = current_article.nextElementSibling; 88 other_article = current_article.nextElementSibling;
@@ -90,10 +91,8 @@ function switchPositions(article_id, direction)
90 other_article = current_article.previousElementSibling; 91 other_article = current_article.previousElementSibling;
91 } 92 }
92 93
93 var other_article_id;
94 try{ 94 try{
95 other_article_id = other_article.querySelector('div[id]').id; 95 other_article_id = other_article.querySelector('div[id]').id;
96 other_article_id = 'i' + other_article_id.slice(1); // peut mieux faire
97 } 96 }
98 catch(error){ 97 catch(error){
99 console.log('Inversion impossible'); 98 console.log('Inversion impossible');
diff --git a/public/js/menu.js b/public/js/menu.js
index 7f48ac9..8f1f326 100644
--- a/public/js/menu.js
+++ b/public/js/menu.js
@@ -15,7 +15,6 @@ function moveOneLevelUp(page_id)
15 .then(data => { 15 .then(data => {
16 if(data.success) 16 if(data.success)
17 { 17 {
18 console.log(data);
19 // affichage 18 // affichage
20 nav_zone.innerHTML = ''; 19 nav_zone.innerHTML = '';
21 nav_zone.insertAdjacentHTML('afterbegin', data.nav); 20 nav_zone.insertAdjacentHTML('afterbegin', data.nav);
@@ -23,7 +22,6 @@ function moveOneLevelUp(page_id)
23 menu_edit_buttons.insertAdjacentHTML('afterbegin', data.menu_buttons); 22 menu_edit_buttons.insertAdjacentHTML('afterbegin', data.menu_buttons);
24 } 23 }
25 else { 24 else {
26
27 console.error('Échec du déplacement'); 25 console.error('Échec du déplacement');
28 } 26 }
29 }) 27 })
@@ -49,7 +47,6 @@ function moveOneLevelDown(page_id)
49 .then(data => { 47 .then(data => {
50 if(data.success) 48 if(data.success)
51 { 49 {
52 console.log(data);
53 // affichage 50 // affichage
54 nav_zone.innerHTML = ''; 51 nav_zone.innerHTML = '';
55 nav_zone.insertAdjacentHTML('afterbegin', data.nav); 52 nav_zone.insertAdjacentHTML('afterbegin', data.nav);
diff --git a/public/js/tinymce.js b/public/js/tinymce.js
index 1e16f6e..d6b0bf8 100644
--- a/public/js/tinymce.js
+++ b/public/js/tinymce.js
@@ -55,7 +55,7 @@ function deleteArticle(id){
55 { 55 {
56 // Supprimer l'article du DOM 56 // Supprimer l'article du DOM
57 const articleElement = document.getElementById(id); 57 const articleElement = document.getElementById(id);
58 articleElement.parentElement.parentElement.remove(); // <article> est deux niveau au dessus 58 findParentByTagName(articleElement, 'article').remove();
59 toastNotify("L'article a été supprimé."); 59 toastNotify("L'article a été supprimé.");
60 } 60 }
61 else{ 61 else{
@@ -106,7 +106,7 @@ class Editor
106 106
107 init(){ 107 init(){
108 tinymce.init({ 108 tinymce.init({
109 selector: `#${this.id}`, // avec un # comme dans querySelector 109 selector: `[id="${this.id}"]`, // écrire [id="246"] au lieu de #246 parce que l'id commence par un chiffre
110 language: 'fr_FR', // téléchargement ici: https://www.tiny.cloud/get-tiny/language-packages/ 110 language: 'fr_FR', // téléchargement ici: https://www.tiny.cloud/get-tiny/language-packages/
111 language_url: 'js/tinymce-langs/fr_FR.js', // ou installer tweeb/tinymce-i18n avec composer 111 language_url: 'js/tinymce-langs/fr_FR.js', // ou installer tweeb/tinymce-i18n avec composer
112 license_key: 'gpl', 112 license_key: 'gpl',
@@ -136,7 +136,7 @@ class Editor
136 if(window.Config.page !== 'article'){ 136 if(window.Config.page !== 'article'){
137 document.getElementById(`position_up-${this.id}`).classList.add('hidden'); 137 document.getElementById(`position_up-${this.id}`).classList.add('hidden');
138 document.getElementById(`position_down-${this.id}`).classList.add('hidden'); 138 document.getElementById(`position_down-${this.id}`).classList.add('hidden');
139 document.getElementById(`delete-${('i' + this.id.slice(1))}`).classList.add('hidden'); 139 document.getElementById(`delete-${this.id}`).classList.add('hidden');
140 } 140 }
141 } 141 }
142 }); 142 });
@@ -259,7 +259,7 @@ class Editor
259 } 259 }
260 260
261 close(restore_old = true){ 261 close(restore_old = true){
262 tinymce.remove(`#${this.id}`); // avec un # comme dans querySelector 262 tinymce.remove(`[id="${this.id}"]`); // comme dans tinymce.init
263 delete editors[this.id]; 263 delete editors[this.id];
264 264
265 // Restaurer le contenu d'origine de l'article 265 // Restaurer le contenu d'origine de l'article
diff --git a/src/URL.php b/src/URL.php
index 689332f..a6d6379 100644
--- a/src/URL.php
+++ b/src/URL.php
@@ -12,6 +12,13 @@ class URL implements Stringable
12 private array $params; 12 private array $params;
13 private string $anchor = ''; 13 private string $anchor = '';
14 14
15 public function __construct(array $gets = [], string $anchor = ''){
16 $this->params = $gets;
17 if($anchor != ''){
18 $this->setAnchor($anchor);
19 }
20 }
21
15 // setters statiques 22 // setters statiques
16 static public function setProtocol(string $protocol = 'http'): void 23 static public function setProtocol(string $protocol = 'http'): void
17 { 24 {
@@ -39,14 +46,7 @@ class URL implements Stringable
39 { 46 {
40 self::$path = '/' . ltrim($path, '/'); 47 self::$path = '/' . ltrim($path, '/');
41 } 48 }
42 49
43 public function __construct(array $gets = [], string $anchor = ''){
44 $this->params = $gets;
45 if($anchor != ''){
46 $this->setAnchor($anchor);
47 }
48 }
49
50 //setters normaux 50 //setters normaux
51 public function addParams(array $gets): void 51 public function addParams(array $gets): void
52 { 52 {
diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php
index 5cebad6..cb132cf 100644
--- a/src/controller/ArticleController.php
+++ b/src/controller/ArticleController.php
@@ -15,6 +15,10 @@ class ArticleController
15 if(json_last_error() === JSON_ERROR_NONE) 15 if(json_last_error() === JSON_ERROR_NONE)
16 { 16 {
17 $id = $json['id']; 17 $id = $json['id'];
18 if(in_array($id[0], ['t', 'p', 'i', 'd'])){
19 $id = substr($id, 1);
20 }
21
18 $director = new Director($entityManager); 22 $director = new Director($entityManager);
19 $content = $json['content']; 23 $content = $json['content'];
20 24
@@ -29,7 +33,7 @@ class ArticleController
29 } 33 }
30 34
31 // nouvel article 35 // nouvel article
32 if($id[0] === 'n') 36 if($json['id'][0] === 'n') // ici $id est un bloc
33 { 37 {
34 $section_id = (int)substr($id, 1); // id du bloc <section> 38 $section_id = (int)substr($id, 1); // id du bloc <section>
35 if(!$director->findNodeById($section_id)){ 39 if(!$director->findNodeById($section_id)){
@@ -40,9 +44,9 @@ class ArticleController
40 $node = $director->getNode(); // = <section> 44 $node = $director->getNode(); // = <section>
41 45
42 if(is_array($content)){ // cas d'une nouvelle "news" 46 if(is_array($content)){ // cas d'une nouvelle "news"
43 $date = new \DateTime($content['d']); 47 $date = new \DateTime($content['d'] . ':' . (new \DateTime)->format('s')); // l'input type="datetime-local" ne donne pas les secondes, on les ajoute: 'hh:mm' . ':ss'
44 $article = new Article($content['i'], $date, $content['t'], $content['p']); 48 $article = new Article($content['i'], $date, $content['t'], $content['p']);
45 $article_node = new Node('new', 'i' . (string)$date->getTimestamp(), [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); 49 $article_node = new Node('new', [], count($node->getChildren()) + 1, $node, $node->getPage(), $article);
46 } 50 }
47 else{ // autres cas 51 else{ // autres cas
48 $timestamp = time(); 52 $timestamp = time();
@@ -50,9 +54,8 @@ class ArticleController
50 $date->setTimestamp($timestamp); 54 $date->setTimestamp($timestamp);
51 55
52 $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD 56 $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD
53
54 $placement = $json['placement'] === 'first' ? 0 : count($node->getChildren()) + 1; // 57 $placement = $json['placement'] === 'first' ? 0 : count($node->getChildren()) + 1; //
55 $article_node = new Node('post', 'i' . (string)$timestamp, [], $placement, $node, $node->getPage(), $article); 58 $article_node = new Node('post', [], $placement, $node, $node->getPage(), $article);
56 59
57 if($json['placement'] === 'first'){ 60 if($json['placement'] === 'first'){
58 $node->addChild($article_node); 61 $node->addChild($article_node);
@@ -63,13 +66,11 @@ class ArticleController
63 $entityManager->persist($article_node); 66 $entityManager->persist($article_node);
64 $entityManager->flush(); 67 $entityManager->flush();
65 68
66 echo json_encode(['success' => true, 'article_id' => $article_node->getArticleTimestamp()]); 69 echo json_encode(['success' => true, 'article_id' => $article_node->getId()]);
67 die; 70 die;
68 } 71 }
69 // modification article 72 // modification article
70 else{ 73 //else{}
71 $id[0] = 'i'; // id de l'article node
72 }
73 74
74 if($director->makeArticleNode($id)) // une entrée est trouvée 75 if($director->makeArticleNode($id)) // une entrée est trouvée
75 { 76 {
@@ -87,9 +88,8 @@ class ArticleController
87 case 'd': 88 case 'd':
88 echo json_encode(['success' => false, 'message' => 'l\'action editor_submit ne supporte pas les dates, utiliser date_submit.']); 89 echo json_encode(['success' => false, 'message' => 'l\'action editor_submit ne supporte pas les dates, utiliser date_submit.']);
89 die; 90 die;
90 default: 91 default: // modif article simple (id sans lettre devant)
91 echo json_encode(['success' => false, 'message' => 'identifiant non utilisable']); 92 $node->getArticle()->setContent($content);
92 die;
93 } 93 }
94 $entityManager->flush(); 94 $entityManager->flush();
95 echo json_encode(['success' => true]); 95 echo json_encode(['success' => true]);
@@ -141,10 +141,9 @@ class ArticleController
141 $section = $director->getNode(); 141 $section = $director->getNode();
142 142
143 $section->sortChildren(true); // régénère les positions avant inversion 143 $section->sortChildren(true); // régénère les positions avant inversion
144
145 $article2 = null; 144 $article2 = null;
146 foreach($section->getChildren() as $child){ 145 foreach($section->getChildren() as $child){
147 if($child->getArticleTimestamp() === $json['id2']) // type string 146 if((string)$child->getId() === $json['id2']) // type string
148 { 147 {
149 $article2 = $child; 148 $article2 = $child;
150 break; 149 break;
@@ -163,8 +162,7 @@ class ArticleController
163 162
164 static public function dateSubmit(EntityManager $entityManager, array $json): void 163 static public function dateSubmit(EntityManager $entityManager, array $json): void
165 { 164 {
166 $id = $json['id']; 165 $id = substr($json['id'], 1);
167 $id[0] = 'i';
168 $date = new DateTime($json['date']); 166 $date = new DateTime($json['date']);
169 167
170 $director = new Director($entityManager); 168 $director = new Director($entityManager);
diff --git a/src/controller/Director.php b/src/controller/Director.php
index 6ee0993..8be9b59 100644
--- a/src/controller/Director.php
+++ b/src/controller/Director.php
@@ -50,7 +50,7 @@ class Director
50 } 50 }
51 else // avec $_GET['id'] dans l'URL 51 else // avec $_GET['id'] dans l'URL
52 { 52 {
53 $dql .= ' OR n.article_timestamp = :id'; 53 $dql .= ' OR n.id_node = :id';
54 $bulk_data = $this->entityManager 54 $bulk_data = $this->entityManager
55 ->createQuery($dql) 55 ->createQuery($dql)
56 ->setParameter('page', $this->page) 56 ->setParameter('page', $this->page)
@@ -105,10 +105,10 @@ class Director
105 public function makeArticleNode(string $id = '', bool $get_section = false): bool 105 public function makeArticleNode(string $id = '', bool $get_section = false): bool
106 { 106 {
107 if($get_section){ 107 if($get_section){
108 $dql = 'SELECT n, p FROM App\Entity\Node n LEFT JOIN n.parent p WHERE n.article_timestamp = :id'; 108 $dql = 'SELECT n, p FROM App\Entity\Node n LEFT JOIN n.parent p WHERE n.id_node = :id';
109 } 109 }
110 else{ 110 else{
111 $dql = 'SELECT n FROM App\Entity\Node n WHERE n.article_timestamp = :id'; 111 $dql = 'SELECT n FROM App\Entity\Node n WHERE n.id_node = :id';
112 } 112 }
113 // n est l'article et p son $parent 113 // n est l'article et p son $parent
114 $bulk_data = $this->entityManager 114 $bulk_data = $this->entityManager
diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php
index 75967eb..3d7edde 100644
--- a/src/controller/PageManagementController.php
+++ b/src/controller/PageManagementController.php
@@ -79,9 +79,7 @@ class PageManagementController
79 $page->setPagePath(ltrim($parent->getPagePath() . '/' . $page->getEndOfPath(), '/')); 79 $page->setPagePath(ltrim($parent->getPagePath() . '/' . $page->getEndOfPath(), '/'));
80 80
81 // noeud "head" 81 // noeud "head"
82 $node = new Node( 82 $node = new Node('head', [],
83 'head',
84 null, [],
85 1, // position d'un head = 1 83 1, // position d'un head = 1
86 null, // pas de parent 84 null, // pas de parent
87 $page); 85 $page);
@@ -163,12 +161,7 @@ class PageManagementController
163 $entityManager->persist($bulk_data[0]); 161 $entityManager->persist($bulk_data[0]);
164 } 162 }
165 163
166 $block = new Node( 164 $block = new Node($_POST["bloc_select"], [], $position, $main, $page);
167 $_POST["bloc_select"],
168 null, [],
169 $position,
170 $main,
171 $page);
172 $data = new NodeData( 165 $data = new NodeData(
173 ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], 166 ['title' => trim(htmlspecialchars($_POST["bloc_title"]))],
174 $block); 167 $block);
diff --git a/src/installation.php b/src/installation.php
index b251c43..0d68e7b 100644
--- a/src/installation.php
+++ b/src/installation.php
@@ -101,21 +101,21 @@ function makeStartPage(EntityManager $entityManager){
101 101
102 /* -- table node -- */ 102 /* -- table node -- */
103 // paramètres: name_node, article_timestamp, attributes, position, parent, page, article 103 // paramètres: name_node, article_timestamp, attributes, position, parent, page, article
104 $head_accueil = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'foot'], 'js_array' => ['main']], 1, NULL, $accueil, NULL); 104 $head_accueil = new Node('head', ['css_array' => ['body', 'head', 'nav', 'foot'], 'js_array' => ['main']], 1, NULL, $accueil, NULL);
105 $head_article = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'foot'], 'js_array' => ['main']], 1, NULL, $article, NULL); 105 $head_article = new Node('head', ['css_array' => ['body', 'head', 'nav', 'foot'], 'js_array' => ['main']], 1, NULL, $article, NULL);
106 $header = new Node('header', NULL, [], 2, NULL, NULL, NULL); 106 $header = new Node('header', [], 2, NULL, NULL, NULL);
107 $nav = new Node('nav', NULL, [], 1, $header, NULL, NULL); 107 $nav = new Node('nav', [], 1, $header, NULL, NULL);
108 $main = new Node('main', NULL, [], 3, NULL, NULL, NULL); 108 $main = new Node('main', [], 3, NULL, NULL, NULL);
109 $footer = new Node('footer', NULL, [], 4, NULL, NULL, NULL); 109 $footer = new Node('footer', [], 4, NULL, NULL, NULL);
110 $breadcrumb = new Node('breadcrumb', NULL, [], 2, $header, NULL, NULL); 110 $breadcrumb = new Node('breadcrumb', [], 2, $header, NULL, NULL);
111 $head_login = new Node('head', NULL, ["stop" => true, 'css_array' => ['body'], 'js_array' => ['main']], 1, NULL, $connection, NULL); 111 $head_login = new Node('head', ["stop" => true, 'css_array' => ['body'], 'js_array' => ['main']], 1, NULL, $connection, NULL);
112 $login = new Node('login', NULL, [], 1, $main, $connection, NULL); 112 $login = new Node('login', [], 1, $main, $connection, NULL);
113 $head_my_account = new Node('head', NULL, ["stop" => true, 'css_array' => ['body'], 'js_array' => ['main']], 1, NULL, $my_account, NULL); 113 $head_my_account = new Node('head', ["stop" => true, 'css_array' => ['body'], 'js_array' => ['main']], 1, NULL, $my_account, NULL);
114 $user_edit = new Node('user_edit', NULL, [], 1, $main, $my_account, NULL); 114 $user_edit = new Node('user_edit', [], 1, $main, $my_account, NULL);
115 $head_edit_menu = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'menu', 'foot'], 'js_array' => ['main', 'menu']], 1, NULL, $menu_paths, NULL); 115 $head_edit_menu = new Node('head', ['css_array' => ['body', 'head', 'nav', 'menu', 'foot'], 'js_array' => ['main', 'menu']], 1, NULL, $menu_paths, NULL);
116 $bloc_edit_menu = new Node('menu', NULL, [], 1, $main, $menu_paths, NULL); 116 $bloc_edit_menu = new Node('menu', [], 1, $main, $menu_paths, NULL);
117 $head_new_page = new Node('head', NULL, ['css_array' => ['body', 'head', 'nav', 'new_page', 'foot'], 'js_array' => ['main', 'new_page']], 1, NULL, $new_page, NULL); 117 $head_new_page = new Node('head', ['css_array' => ['body', 'head', 'nav', 'new_page', 'foot'], 'js_array' => ['main', 'new_page']], 1, NULL, $new_page, NULL);
118 $bloc_new_page = new Node('new_page', NULL, [], 1, $main, $new_page, NULL); 118 $bloc_new_page = new Node('new_page', [], 1, $main, $new_page, NULL);
119 119
120 /* -- table presentation -- */ 120 /* -- table presentation -- */
121 $fullwidth = new Presentation('fullwidth'); 121 $fullwidth = new Presentation('fullwidth');
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php
index 7cf395c..eb73116 100644
--- a/src/model/entities/Node.php
+++ b/src/model/entities/Node.php
@@ -17,7 +17,7 @@ class Node
17 #[ORM\Id] 17 #[ORM\Id]
18 #[ORM\GeneratedValue] 18 #[ORM\GeneratedValue]
19 #[ORM\Column(type: "integer")] 19 #[ORM\Column(type: "integer")]
20 private int $id_node; 20 private ?int $id_node = null;
21 21
22 #[ORM\Column(type: "string", length: 255)] 22 #[ORM\Column(type: "string", length: 255)]
23 private string $name_node; 23 private string $name_node;
@@ -52,16 +52,14 @@ class Node
52 private ?NodeData $node_data = null; 52 private ?NodeData $node_data = null;
53 53
54 54
55 // -- fin des attributs destinés à doctrine, début du code utilisateur -- 55 // attributs non destinés à doctrine
56
57 private array $children = []; // tableau de Node 56 private array $children = []; // tableau de Node
58 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" 57 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article"
59 static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot'],'js_array' => ['main']]; 58 static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot'],'js_array' => ['main']];
60 59
61 public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) 60 public function __construct(string $name = '', array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null)
62 { 61 {
63 $this->name_node = $name; 62 $this->name_node = $name;
64 $this->article_timestamp = $article_timestamp;
65 $this->attributes = $attributes; 63 $this->attributes = $attributes;
66 $this->position = $position; 64 $this->position = $position;
67 $this->parent = $parent; 65 $this->parent = $parent;
@@ -70,7 +68,7 @@ class Node
70 } 68 }
71 69
72 // pfff... 70 // pfff...
73 public function getId(): int 71 public function getId(): ?int
74 { 72 {
75 return $this->id_node; 73 return $this->id_node;
76 } 74 }
diff --git a/src/router.php b/src/router.php
index 326a637..04441a9 100644
--- a/src/router.php
+++ b/src/router.php
@@ -306,20 +306,23 @@ else{
306 306
307/* -- utilisation de la réponse -- */ 307/* -- utilisation de la réponse -- */
308if(isset($response)){ 308if(isset($response)){
309 // cas des mauvais id de la page article (d'autres cas à prévoir)
309 if($request->isMethod('GET') && $response->getStatusCode() == 302){ // 302 redirection temporaire 310 if($request->isMethod('GET') && $response->getStatusCode() == 302){ // 302 redirection temporaire
310 // ne gère pour l'instant que les mauvais id de la page article
311 header('Location: ' . new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil'])); 311 header('Location: ' . new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil']));
312 } 312 }
313 // redirection après traitement de formulaires HTTP
313 elseif($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){ 314 elseif($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){
314 $response_data = json_decode(($response)->getContent(), true); 315 $response_data = json_decode(($response)->getContent(), true);
315 $url = new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil']); 316 $url = new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil']);
316 $url->addParams(['success' => $response_data['success'], 'message' => $response_data['message']]); 317 $url->addParams(['success' => $response_data['success'], 'message' => $response_data['message']]);
317 header('Location: ' . $url); 318 header('Location: ' . $url);
318 } 319 }
320 // affichage d'une page OU requête AJAX
319 else{ 321 else{
320 $response->send(); 322 $response->send();
321 } 323 }
322} 324}
325// pas utilisation de RESPONSE (cas destiné à disparaître)
323else{ 326else{
324 if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){ 327 if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded'){
325 header("Location: " . new URL(['error' => 'erreur côté serveur'])); 328 header("Location: " . new URL(['error' => 'erreur côté serveur']));
diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php
index e6fc61a..8a40d82 100644
--- a/src/view/MainBuilder.php
+++ b/src/view/MainBuilder.php
@@ -23,11 +23,13 @@ class MainBuilder extends AbstractBuilder
23 die; 23 die;
24 } 24 }
25 25
26 // nouvel article
26 if($node->getAdoptedChild() == null){ 27 if($node->getAdoptedChild() == null){
27 $date = new \DateTime; 28 $date = new \DateTime;
28 $article = new Article('', $date); 29 $article = new Article('', $date);
29 $new = new Node('new', 'i' . (string)$date->getTimestamp(), [], 0, null, null, $article); 30 $new = new Node('new', [], 0, null, null, $article);
30 } 31 }
32 // modification
31 else{ 33 else{
32 $new = $node->getAdoptedChild(); 34 $new = $node->getAdoptedChild();
33 } 35 }
diff --git a/src/view/NewBuilder.php b/src/view/NewBuilder.php
index 332d92b..9965d15 100644
--- a/src/view/NewBuilder.php
+++ b/src/view/NewBuilder.php
@@ -9,31 +9,47 @@ class NewBuilder extends AbstractBuilder
9{ 9{
10 static public bool $new_article_mode = false; 10 static public bool $new_article_mode = false;
11 11
12 public function __construct(Node $node, ) 12 public function __construct(Node $node)
13 { 13 {
14 $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; 14 $viewFile = self::VIEWS_PATH . $node->getName() . '.php';
15 15
16 if(file_exists($viewFile)) 16 if(file_exists($viewFile))
17 { 17 {
18 // id (timestamp) 18 if(self::$new_article_mode){
19 if(!empty($node->getAttributes())) 19 $id = $_GET['id']; // ici l'id est le nom du block news_block parent
20 { 20 $title = '';
21 extract($node->getAttributes()); 21 $preview = '';
22
23 // lettre au début de l'id: t = title, p = preview, i = article, d = date
24 $id_title = $id;
25 $id_title[0] = 't';
26 $id_preview = $id;
27 $id_preview[0] = 'p';
28 $id_content = 'i' . $id;
29 $id_content[0] = 'i';
30 $id_date = $id;
31 $id_date[0] = 'd';
22 } 32 }
33 else{
34 $id = (string)$node->getId();
23 35
24 // html, date 36 // id (timestamp)
25 $title = $node->getArticle()->getTitle(); 37 if(!empty($node->getAttributes()))
26 $preview = $node->getArticle()->getPreview(); 38 {
27 39 extract($node->getAttributes());
28 // lettre au début de l'id: i = article, p = preview, t = title, d = date 40 }
29 $id = $node->getArticleTimestamp();
30 $id_title = $id;
31 $id_title[0] = 't';
32 $id_preview = $id;
33 $id_preview[0] = 'p';
34 $id_date = $id;
35 $id_date[0] = 'd';
36 41
42 // html, date
43 $title = $node->getArticle()->getTitle();
44 $preview = $node->getArticle()->getPreview();
45
46 // lettre au début de l'id: t = title, p = preview, i = article, d = date
47 $id_title = 't' . $id;
48 $id_preview = 'p' . $id;
49 $id_content = 'i' . $id;
50 $id_date = 'd' . $id;
51 }
52
37 $content = ''; 53 $content = '';
38 54
39 // page article unique 55 // page article unique
@@ -85,12 +101,12 @@ class NewBuilder extends AbstractBuilder
85 $submit_preview = '<p id="submit-' . $id_preview . '" class="hidden"><button ' . $submit_js_preview . '>Valider</button></p>'; 101 $submit_preview = '<p id="submit-' . $id_preview . '" class="hidden"><button ' . $submit_js_preview . '>Valider</button></p>';
86 $preview_buttons = '<div class="button_zone">' . $modify_preview . $close_editor_preview . $submit_preview . '</div>'; 102 $preview_buttons = '<div class="button_zone">' . $modify_preview . $close_editor_preview . $submit_preview . '</div>';
87 103
88 $article_js = 'onclick="openEditor(\'' . $id . '\')"'; 104 $article_js = 'onclick="openEditor(\'' . $id_content . '\')"';
89 $modify_article = '<p id="edit-' . $id . '"><button ' . $article_js . '><img class="action_icon" src="assets/edit.svg">Article</button></p>' . "\n"; 105 $modify_article = '<p id="edit-' . $id_content . '"><button ' . $article_js . '><img class="action_icon" src="assets/edit.svg">Article</button></p>' . "\n";
90 $close_js_article = 'onclick="closeEditor(\'' . $id . '\')"'; 106 $close_js_article = 'onclick="closeEditor(\'' . $id_content . '\')"';
91 $close_editor_article = '<p id="cancel-' . $id . '" class="hidden"><button ' . $close_js_article . '>Annuler</button></p>'; 107 $close_editor_article = '<p id="cancel-' . $id_content . '" class="hidden"><button ' . $close_js_article . '>Annuler</button></p>';
92 $submit_js_article = 'onclick="submitArticle(\'' . $id . '\')"'; 108 $submit_js_article = 'onclick="submitArticle(\'' . $id_content . '\')"';
93 $submit_article = '<p id="submit-' . $id . '" class="hidden"><button ' . $submit_js_article . '>Valider</button></p>'; 109 $submit_article = '<p id="submit-' . $id_content . '" class="hidden"><button ' . $submit_js_article . '>Valider</button></p>';
94 $article_buttons = '<div class="button_zone">' . $modify_article . $close_editor_article . $submit_article . '</div>'; 110 $article_buttons = '<div class="button_zone">' . $modify_article . $close_editor_article . $submit_article . '</div>';
95 111
96 $date_js = 'onclick="changeDate(\'' . $id_date . '\', \'article\');'; 112 $date_js = 'onclick="changeDate(\'' . $id_date . '\', \'article\');';
diff --git a/src/view/PostBuilder.php b/src/view/PostBuilder.php
index ae5cc9b..70a2d77 100644
--- a/src/view/PostBuilder.php
+++ b/src/view/PostBuilder.php
@@ -22,7 +22,7 @@ class PostBuilder extends AbstractBuilder
22 // html 22 // html
23 $title = $node->getArticle()->getTitle(); 23 $title = $node->getArticle()->getTitle();
24 $html = $node->getArticle()->getContent(); 24 $html = $node->getArticle()->getContent();
25 $id = $node->getArticleTimestamp(); 25 $id = (string)$node->getId();
26 26
27 // partage 27 // partage
28 $share_link = new URL(['page' => CURRENT_PAGE], $id); 28 $share_link = new URL(['page' => CURRENT_PAGE], $id);
diff --git a/src/view/templates/new.php b/src/view/templates/new.php
index 1b25eba..fadf1a2 100644
--- a/src/view/templates/new.php
+++ b/src/view/templates/new.php
@@ -1,6 +1,6 @@
1<?php declare(strict_types=1); ?> 1<?php declare(strict_types=1); ?>
2<article> 2<article>
3 <div class="new_content"> 3 <div class="new_content" id="<?= $id ?>">
4 <div class="article_title_zone"> 4 <div class="article_title_zone">
5 <?= $share_button ?> 5 <?= $share_button ?>
6 <div class="data" id="<?= $id_title ?>"> 6 <div class="data" id="<?= $id_title ?>">
@@ -12,7 +12,7 @@
12 <?= $preview ?> 12 <?= $preview ?>
13 </div> 13 </div>
14 <?= $preview_buttons ?> 14 <?= $preview_buttons ?>
15 <div class="data article_content_text" id="<?= $id ?>"> 15 <div class="data article_content_text" id="<?= $id_content ?>">
16 <?= $content ?> 16 <?= $content ?>
17 </div> 17 </div>
18 <?= $article_buttons ?> 18 <?= $article_buttons ?>