From 86c2a611e55c9e35384febecf34964e214c0296e Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 22 Jul 2021 03:49:28 +0200 Subject: patch modifs --- controller/admin.php | 31 ++----------------------------- controller/ckeditor.php | 12 +++++------- controller/visitor.php | 4 +--- 3 files changed, 8 insertions(+), 39 deletions(-) (limited to 'controller') diff --git a/controller/admin.php b/controller/admin.php index 77ab34e..a35f28a 100644 --- a/controller/admin.php +++ b/controller/admin.php @@ -9,7 +9,6 @@ function melaineEdit($numArticle) $page_actuelle = "melaine"; // tableau $articles[] - require('model/melaine-read.php'); $croissant = False; $articles = lireArticles($page_actuelle, $croissant); @@ -17,46 +16,20 @@ function melaineEdit($numArticle) { $title = "Ajouter un article"; $texte = ''; - //$numArticle = count($articles) + 1; } else { $title = "Modifier un article"; - // faire correspondre le numéro de l'article du GET et le tableau des articles qui est inversé - $texte = $articles[count($articles) - $numArticle]; + $texte = lireUnArticle($_SESSION['nomFichier']); } // traitements PHP pour l'éditeur require('controller/ckeditor.php'); // sécurisation du contenu pré-existant inséré dans l'éditeur - $initial = preparationCKeditor($numArticle, $texte); + $texte = preparationCKeditor($numArticle, $texte); // NB: penser à ajouter au template la fonctionnalité "autosave" // https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/saving-data.html - - // if($numArticle > $nombreDarticles || $numArticle < 0) // erreur nombre trop grand (bug?) - // { - // header('Location: index.php?page=melaine'); - // } - // elseif($numArticle == 0) // nouvel article - // { - // $texte = ''; - // $numArticle = $nombreDarticles + 1; - // } - // else // modification d'un article - // { - // $texte = $articles[$numArticle - 1]; - // } - - - // if($initial == '') - // { - // $article = "nouveau"; - // } - // else - // { - // $article = "modif"; - // } // variable $editeurHTML, $initial est inséré dedans require('view/template-ckeditor.php'); diff --git a/controller/ckeditor.php b/controller/ckeditor.php index 013d6b5..ea90726 100644 --- a/controller/ckeditor.php +++ b/controller/ckeditor.php @@ -33,7 +33,8 @@ function preparationCKeditor($numArticle, $texte) } // réception du HTML créé par l'éditeur -function submitCKeditor($page, $article, $contenuPOST) +// le nom du fichier est celui dans $_SESSION['nomFichier'] +function submitCKeditor($page, $nomFichier, $contenu) { // déjà fait mais on ne sait jamais if(!isset($_SESSION['admin']) || $_SESSION['admin'] != 1) @@ -44,14 +45,12 @@ function submitCKeditor($page, $article, $contenuPOST) { // ne pas continuer si la variable est vide (javascript mal supporté ou utilisation de IE, bug?, erreur de l'utilisateur) // on évitera de perdre un article existant par erreur !! - if($contenuPOST == '') + if($contenu == '') { header('Location: index.php?page=' . $page . '&erreur=contenu_vide'); } else { - $contenu = $_POST["contenu"]; - // récupérer les liens multimedia //require("media.php"); //$contenu = mediaSubmit($contenu); @@ -89,14 +88,13 @@ function submitCKeditor($page, $article, $contenuPOST) // enregistrement require('model/melaine-write.php'); - if($article == 0) + if($_GET['article'] == 0) { nouvelArticle($page, $contenu); } else { - // $article est le nom du fichier - modifArticle($page, $article, $contenu); + modifArticle($page, $nomFichier, $contenu); } // debuggage diff --git a/controller/visitor.php b/controller/visitor.php index 9bd3461..a08ea95 100644 --- a/controller/visitor.php +++ b/controller/visitor.php @@ -33,13 +33,11 @@ function melaineVisitor() $title = "Mais qui est Melaine Favennec?"; // tableau $articles - require('model/melaine-read.php'); $croissant = False; $articles = lireArticles($page_actuelle, $croissant); // vérification pour protéger les visiteurs - // normalement déjà faite dans submit.php, - // c'est au cas où les données aient été trafiquées + // normalement déjà faite dans submit.php, au cas où la base a été trafiquée //$article = htmLawed($article); // variables $css, $js et $content -- cgit v1.2.3