From 63759dbbf023daa8f7f310b914a04310a4770154 Mon Sep 17 00:00:00 2001 From: git-pc-greta Date: Thu, 30 Jan 2025 14:52:59 +0100 Subject: =?UTF-8?q?foreach=20articles,=20mod=C3=A8le=20et=20id=20=C3=A0=20?= =?UTF-8?q?l'ext=C3=A9rieur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index f388081..d998d96 100644 --- a/index.php +++ b/index.php @@ -25,35 +25,48 @@ if(isset($_GET['action']) && $_GET['action'] === 'upload_image_editor') if(isset($_GET['action']) && $_GET['action'] === 'submit_editor') // HTML envoyé par l'éditeur { $ckeditor->setFrom($from); - $ckeditor->setIdArticle($id_article); $ckeditor->checkSubmitPOST(); } -/*$articles = []; -foreach($articles as $article) -{}*/ - -// ouvrir l'éditeur -if(isset($_GET['action']) && $_GET['action'] === 'open_editor') +// modèle - récupération des articles +$articles_id = []; // noms des id en BBD ou des fichiers +$articles_content = []; // contenu HTML +if($ckeditor->getStorageMode() === 'database') { - $ckeditor->setIdArticle($id_article); - $editeurHTML = $ckeditor->openEditor(); + // => modèle } -else // affichage article +elseif($ckeditor->getStorageMode() === 'files') { - $ckeditor->setIdArticle('1646148841'); - if($ckeditor->getStorageMode() === 'database') + foreach(scandir(CKEditor::DATA_PATH . '/html/') as $file_name) { - // ton code + if(str_ends_with($file_name, '.html')) // filtre . et .. et d'éventuels autres fichiers + { + $articles_id[] = rtrim($file_name, '.html'); + } } - elseif($ckeditor->getStorageMode() === 'files') + foreach($articles_id as $id) { - $texte = file_get_contents($ckeditor->getDataPath() . '/html/' . $ckeditor->getIdArticle() . '.html'); - //$texte = trim(addcslashes($texte, "'")); // échappe seulement les simples quotes - $texte = trim($texte); + $texte = trim(file_get_contents(CKEditor::DATA_PATH . '/html/' . $id . '.html')); + //$texte = addslashes($texte); // échappe ', ", \ et NULL, je sais pas si c'est bien + + // ouvrir l'éditeur sur un des articles ou aucun + if(isset($_GET['action']) && $_GET['action'] === 'open_editor') + { + if($id === $id_article) + { + $texte = addcslashes($texte, "'"); // échapper les simples quotes pour javascript + $articles_content[] = $ckeditor->openEditor($id, $texte); + } + else + { + $articles_content[] = $ckeditor->displayArticle($id, $texte); + } + } + else // affichage article + { + $articles_content[] = $ckeditor->displayArticle($id, $texte); + } } - $editeurHTML = '
' . $texte . '
-

ouvrir l\'éditeur

'; } require 'src/view/templates/page.php'; -- cgit v1.2.3