From 13f24b014d07ab3f28c7a8ede4f4bd6eaebbaad4 Mon Sep 17 00:00:00 2001 From: git-pc-greta Date: Mon, 3 Feb 2025 01:09:04 +0100 Subject: bouton nouvel article, file_put_contents, setLanguage() --- index.php | 56 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index a7815be..f33b47b 100644 --- a/index.php +++ b/index.php @@ -1,14 +1,14 @@ setLanguage('fr'); // attention, exécute une autre fonction qui peut échouer $ckeditor->setStorageMode('files'); $ckeditor->setPage($page); @@ -18,19 +18,46 @@ $ckeditor->setPage($page); // upload images AJAX if(isset($_GET['action']) && $_GET['action'] === 'upload_image_editor') { - $ckeditor->checkAjaxReqest(); + $ckeditor->checkAjaxRequest(); } // submit normal -if(isset($_GET['action']) && $_GET['action'] === 'submit_editor') // HTML envoyé par l'éditeur +if(isset($_GET['action']) && $_GET['action'] === 'submit_editor' && isset($_POST["contenu"])) // HTML envoyé par l'éditeur { $ckeditor->setFrom($from); - $ckeditor->checkSubmitPOST(); + $html_from_editor = $ckeditor->checkSubmitPOST(); + + if($id_article == '') // nouvel article + { + $id_article = time(); + } + + if($ckeditor->getStorageMode() === 'database') + { + // => modèle + } + elseif($ckeditor->getStorageMode() === 'files') + { + file_put_contents(CKEditor::DATA_PATH . '/html/' . $id_article . '.html', $html_from_editor); + } + + header('Location: index.php?page=' . $ckeditor->getFrom()); + die; } // modèle - récupération des articles -$articles_id = []; // noms des id en BBD ou des fichiers +$id_array = []; // noms des id en BBD ou des fichiers $articles_content = []; // contenu HTML + +if(isset($_GET['action']) && $_GET['action'] === 'open_editor' && $id_article == '') +{ + $articles_content = $ckeditor->openEditor() . "\n"; +} +else +{ + $articles_content = $ckeditor->displayNewArticleButton() . "\n"; +} + if($ckeditor->getStorageMode() === 'database') { // => modèle @@ -41,10 +68,10 @@ elseif($ckeditor->getStorageMode() === 'files') { if(str_ends_with($file_name, '.html')) // filtre . et .. et d'éventuels autres fichiers { - $articles_id[] = rtrim($file_name, '.html'); + $id_array[] = rtrim($file_name, '.html'); } } - foreach($articles_id as $id) + foreach($id_array as $id) { $texte = trim(file_get_contents(CKEditor::DATA_PATH . '/html/' . $id . '.html')); //$texte = addslashes($texte); // échappe ', ", \ et NULL, je sais pas si c'est bien @@ -55,16 +82,16 @@ elseif($ckeditor->getStorageMode() === 'files') if($id === $id_article) { $texte = addcslashes($texte, "'"); // échapper les simples quotes pour javascript - $articles_content[] = $ckeditor->openEditor($id, $texte); + $articles_content .= $ckeditor->openEditor($id, $texte) . "\n"; } else { - $articles_content[] = $ckeditor->displayArticle($id, $texte); + $articles_content .= $ckeditor->displayArticle($id, $texte) . "\n"; } } else { - $articles_content[] = $ckeditor->displayArticle($id, $texte); + $articles_content .= $ckeditor->displayArticle($id, $texte) . "\n"; } } } @@ -81,12 +108,7 @@ elseif($ckeditor->getStorageMode() === 'files')
- +
-- cgit v1.2.3