From fa3c582a2bd91433399a5b275616052028a5a011 Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 18 Sep 2025 00:27:20 +0200 Subject: =?UTF-8?q?news=20positionn=C3=A9es=20en=20fonction=20de=20leur=20?= =?UTF-8?q?date,=20suppression=20de=20leurs=20boutons=20position,=20am?= =?UTF-8?q?=C3=A9liorations=20routage=20page=20article,=20bouton=20share?= =?UTF-8?q?=20en=20bas=20pour=20les=20news?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/css/body.css | 12 ++++++------ public/js/tinymce.js | 6 +++++- src/controller/ArticleController.php | 11 ++++++++--- src/controller/ViewController.php | 25 ++++++++++++++++--------- src/model/entities/Node.php | 26 +++++++++++++++++++++++++- src/router.php | 5 ++--- src/view/NewBuilder.php | 34 +++++++++++----------------------- src/view/NewsBlockBuilder.php | 8 +------- src/view/templates/new.php | 1 - 9 files changed, 74 insertions(+), 54 deletions(-) diff --git a/public/css/body.css b/public/css/body.css index d60f28c..f8e4f81 100644 --- a/public/css/body.css +++ b/public/css/body.css @@ -7,10 +7,6 @@ body background-color: #0cceec; } -.hidden{ - display: none; -} - #bloc_page {} @@ -176,8 +172,7 @@ button .action_icon:hover } .delete_button { - float: right; - margin-left: 2px; + margin-right: 2px; } section button, section input[type=submit] { @@ -238,4 +233,9 @@ article a:hover { grid-template-columns: repeat(2, 1fr); } +} + +.article_admin_zone p +{ + align-self: center; } \ No newline at end of file diff --git a/public/js/tinymce.js b/public/js/tinymce.js index d6b0bf8..81ba8ea 100644 --- a/public/js/tinymce.js +++ b/public/js/tinymce.js @@ -332,7 +332,11 @@ class Editor content = this.tiny_instance.getContent(); } - let fetch_params = {id: this.id, content: content}; + let fetch_params = { + id: this.id, + content: content, + from: new URLSearchParams(window.location.search).get('from') // le "$_GET" de javascript + }; if(this.placement){ fetch_params['placement'] = this.placement; } diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php index cb132cf..411c1dc 100644 --- a/src/controller/ArticleController.php +++ b/src/controller/ArticleController.php @@ -36,14 +36,19 @@ class ArticleController if($json['id'][0] === 'n') // ici $id est un bloc { $section_id = (int)substr($id, 1); // id du bloc
- if(!$director->findNodeById($section_id)){ - echo json_encode(['success' => false, 'error' => 'article_not_saved']); + if(!$director->findNodeById($section_id)){ // erreur mauvais id + echo json_encode(['success' => false, 'error' => 'article_not_saved, bad id']); die; } $director->makeSectionNode(); $node = $director->getNode(); // =
- + if(is_array($content)){ // cas d'une nouvelle "news" + if($node->getPage()->getEndOfPath() !== $json['from']){ // erreur mauvais from + echo json_encode(['success' => false, 'error' => 'article_not_saved, bad from']); + die; + } + $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' $article = new Article($content['i'], $date, $content['t'], $content['p']); $article_node = new Node('new', [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); diff --git a/src/controller/ViewController.php b/src/controller/ViewController.php index 668fa25..f66baff 100644 --- a/src/controller/ViewController.php +++ b/src/controller/ViewController.php @@ -33,17 +33,24 @@ class ViewController extends AbstractBuilder // ViewController est aussi le prem } // page article: mode création et erreurs d'id - if($_SESSION['admin'] && $request->query->has('page') && $request->query->get('page') === 'article'){ - if(!$request->query->has('id')){ - return new Response($this->html, 302); - } - else{ - if($request->query->get('id')[0] === 'n'){ // mode création d'article (vérification de l'id du bloc dans ArticleController) - NewBuilder::$new_article_mode = true; - } - elseif(self::$root_node->getNodeByName('main')->getAdoptedChild() === null){ // id inconnu + if($request->query->has('page') && $request->query->get('page') === 'article'){ + if($_SESSION['admin']){ + if(!$request->query->has('id')){ return new Response($this->html, 302); } + else{ + // mode création d'article + // l'id du bloc et 'from=' sont vérifiés dans ArticleController::editorSubmit + if($request->query->get('id')[0] === 'n' && $request->query->has('from') && !empty($request->query->get('from'))){ + NewBuilder::$new_article_mode = true; + } + elseif(self::$root_node->getNodeByName('main')->getAdoptedChild() === null){ // id inconnu + return new Response($this->html, 302); + } + } + } + elseif($request->query->get('id')[0] === 'n'){ // accès page nouvelle article interdit sans être admin + return new Response($this->html, 302); } } diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index eb73116..c5df8d1 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php @@ -171,7 +171,31 @@ class Node public function addChild(self $child): void { $this->children[] = $child; - $this->sortChildren(false); + + // cas particulier des news: utilise les dates au lieu des positions (les positions existent mais sont ignorées) + if($this->getName() === 'news_block'){ + $this->sortNews($this->getNodeData()->getData()['chrono'] ?? false); // faux = ordre chronologique + } + else{ + $this->sortChildren(false); + } + } + + private function sortNews(bool $chrono = false) // affichage du plus récent au plus ancien par défaut + { + // tri par insertion similaire à Position::sortChildren + for($i = 1; $i < count($this->children); $i++){ + $tmp = $this->children[$i]; + $j = $i - 1; + + $compare = $chrono ? fn($a, $b) => $a > $b : fn($a, $b) => $a < $b; + + while($j >= 0 && $compare($this->children[$j]->getArticle()->getDateTime(), $tmp->getArticle()->getDateTime())){ + $this->children[$j + 1] = $this->children[$j]; + $j--; + } + $this->children[$j + 1] = $tmp; + } } public function removeChild(self $child): void diff --git a/src/router.php b/src/router.php index ccab426..8c33d6e 100644 --- a/src/router.php +++ b/src/router.php @@ -83,8 +83,7 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){ // requêtes JSON avec fetch() if($_SERVER['CONTENT_TYPE'] === 'application/json') { - $data = file_get_contents('php://input'); - $json = json_decode($data, true); + $json = json_decode($request->getContent(), true); // = json_decode(file_get_contents('php://input'), true); if($request->query->has('action')) { @@ -309,7 +308,7 @@ else{ /* -- utilisation de la réponse -- */ if(isset($response)){ - // cas des mauvais id de la page article (d'autres cas à prévoir) + // cas gérés (d'autres sont à prévoir): mauvais id de la page article, accès page création d'article sans être admin if($request->isMethod('GET') && $response->getStatusCode() == 302){ // 302 redirection temporaire header('Location: ' . new URL(['page' => !empty($_GET['from']) ? $_GET['from'] : 'accueil'])); } diff --git a/src/view/NewBuilder.php b/src/view/NewBuilder.php index 9965d15..cd5534b 100644 --- a/src/view/NewBuilder.php +++ b/src/view/NewBuilder.php @@ -55,7 +55,7 @@ class NewBuilder extends AbstractBuilder // page article unique if(Director::$page_path->getLast()->getEndOfPath() === 'article'){ $content = $node->getArticle()->getContent(); - $from_to_button = '

'; + $from_to_button = '

'; } else{ $from_to_button = '

'; @@ -82,8 +82,7 @@ class NewBuilder extends AbstractBuilder $article_buttons = ''; $date_buttons = ''; $admin_buttons = ''; - if($_SESSION['admin']) - { + if($_SESSION['admin']){ if(Director::$page_path->getLast()->getEndOfPath() === 'article'){ $title_js = 'onclick="openEditor(\'' . $id_title . '\')"'; $modify_title = '

' . "\n"; @@ -122,45 +121,34 @@ class NewBuilder extends AbstractBuilder $delete_article = ''; // valider la création d'un nouvel article $submit_js = 'onclick="submitArticle(\'' . $_GET['id'] . '\')"'; - $submit_article = '

' . "\n"; + $submit_article = '

' . "\n"; } // mode article existant else{ $url = new URL(['action' => 'delete_article', 'id' => $_GET['id'], 'from' => $_GET['from'] ?? '']); - $delete_article = '
-

-
' . "\n"; + $delete_article = '
+

+ Supprimer l\'article +

' . "\n"; // this.closest('form').submit() = submit du formulaire avec javascript $submit_article = ''; } - $admin_buttons = $delete_article . $from_to_button . $submit_article; + $admin_buttons = $share_button . $delete_article . $submit_article . $from_to_button; } // autre page else{ - $modify_article = '

' . "\n"; - - $up_js = 'onclick="switchPositions(\'' . $id . '\', \'up\')"'; - $up_button = '

' . "\n"; - - $down_js = 'onclick="switchPositions(\'' . $id . '\', \'down\')"'; - $down_button = '

' . "\n"; - $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; $delete_article = '

' . "\n"; $close_editor = ''; $submit_article = ''; - $submit_article = ''; - - $admin_buttons = $from_to_button . $modify_article . $up_button . $down_button . $delete_article . $close_editor . $submit_article; + $admin_buttons = $from_to_button . $share_button . $delete_article . $close_editor . $submit_article; } } else{ - $admin_buttons = $from_to_button; + $admin_buttons = $share_button . $from_to_button; } ob_start(); diff --git a/src/view/NewsBlockBuilder.php b/src/view/NewsBlockBuilder.php index 76e42c5..e7bbec9 100644 --- a/src/view/NewsBlockBuilder.php +++ b/src/view/NewsBlockBuilder.php @@ -41,12 +41,6 @@ class NewsBlockBuilder extends AbstractBuilder $modify_js = 'onclick="openEditor(\'' . $id . '\')"'; $modify_article = '' . "\n"; - - $up_js = 'onclick="switchPositions(\'' . $id . '\', \'up\')"'; - $up_button = '' . "\n"; - - $down_js = 'onclick="switchPositions(\'' . $id . '\', \'down\')"'; - $down_button = '' . "\n"; $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; $delete_article = '' . "\n"; @@ -58,7 +52,7 @@ class NewsBlockBuilder extends AbstractBuilder $submit_article = ''; $html = ''; - $admin_buttons = $new_button . $modify_article . $up_button . $down_button . $delete_article . $close_editor . $submit_article; + $admin_buttons = $new_button . $modify_article . $delete_article . $close_editor . $submit_article; // post vide mis là pour le bouton "Nouvel article" => déplace vers page "article" ob_start(); diff --git a/src/view/templates/new.php b/src/view/templates/new.php index fadf1a2..bda7daf 100644 --- a/src/view/templates/new.php +++ b/src/view/templates/new.php @@ -2,7 +2,6 @@
-
-- cgit v1.2.3